Upcast to AbstractArguments to avoid instantiating methods

This reduced compilation times when using a large amount of Arguments types.
This commit is contained in:
Michael Miller 2022-07-10 21:54:25 -06:00
parent 32a9bfd356
commit ecab2dd37e
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 6 additions and 6 deletions

View file

@ -18,12 +18,12 @@ module Spectator
end
# Constructs an instance from literal arguments.
def self.capture(*args, **kwargs) : self
new(args, kwargs)
def self.capture(*args, **kwargs) : AbstractArguments
new(args, kwargs).as(AbstractArguments)
end
# Instance of empty arguments.
class_getter empty : Arguments(Tuple(), NamedTuple()) = capture
class_getter empty : AbstractArguments = capture
# Returns the positional argument at the specified index.
def [](index : Int)

View file

@ -11,12 +11,12 @@ module Spectator
getter arguments : AbstractArguments
# Creates a method call.
def initialize(@method : Symbol, @arguments : Arguments = Arguments.empty)
def initialize(@method : Symbol, @arguments : AbstractArguments = Arguments.empty)
end
# Creates a method call by splatting its arguments.
def self.capture(method : Symbol, *args, **kwargs)
arguments = Arguments.new(args, kwargs)
arguments = Arguments.new(args, kwargs).as(AbstractArguments)
new(method, arguments)
end

View file

@ -29,7 +29,7 @@ module Spectator
module StubModifiers
# Returns a new stub with an argument constraint.
def with(*args, **kwargs, &block : AbstractArguments -> T) forall T
constraint = Arguments.new(args, kwargs)
constraint = Arguments.new(args, kwargs).as(AbstractArguments)
ProcStub(T).new(method, block, constraint, location)
end
end