From d98bc05b8804a8902e428aac224dc623725871cb Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 6 Oct 2018 10:09:39 -0600 Subject: [PATCH] Switch to structs to reduce memory allocations --- src/spectator/expectations/expectation.cr | 2 +- src/spectator/expectations/expectation_partial.cr | 2 +- src/spectator/expectations/value_expectation.cr | 2 +- src/spectator/expectations/value_expectation_partial.cr | 2 +- src/spectator/matchers/equality_matcher.cr | 2 +- src/spectator/matchers/matcher.cr | 2 +- src/spectator/matchers/value_matcher.cr | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/spectator/expectations/expectation.cr b/src/spectator/expectations/expectation.cr index 8d33f53..0768d60 100644 --- a/src/spectator/expectations/expectation.cr +++ b/src/spectator/expectations/expectation.cr @@ -20,7 +20,7 @@ module Spectator::Expectations end # Information regarding the outcome of an expectation. - class Result + struct Result # Indicates whether the expectation was satisifed or not. getter? successful : Bool diff --git a/src/spectator/expectations/expectation_partial.cr b/src/spectator/expectations/expectation_partial.cr index 66f2426..99d6523 100644 --- a/src/spectator/expectations/expectation_partial.cr +++ b/src/spectator/expectations/expectation_partial.cr @@ -4,7 +4,7 @@ module Spectator::Expectations # The part of the expectation this class covers is the actual value. # This can also cover a block's behavior. # Sub-types of this class are returned by the `DSL::ExampleDSL.expect` call. - abstract class ExpectationPartial + abstract struct ExpectationPartial # User-friendly string displayed for the actual expression being tested. # For instance, in the expectation: # ``` diff --git a/src/spectator/expectations/value_expectation.cr b/src/spectator/expectations/value_expectation.cr index 7fab54d..49334a4 100644 --- a/src/spectator/expectations/value_expectation.cr +++ b/src/spectator/expectations/value_expectation.cr @@ -1,7 +1,7 @@ require "./expectation" module Spectator::Expectations - class ValueExpectation(ActualType, ExpectedType) + struct ValueExpectation(ActualType, ExpectedType) include Expectation def initialize(@partial : ValueExpectationPartial(ActualType), diff --git a/src/spectator/expectations/value_expectation_partial.cr b/src/spectator/expectations/value_expectation_partial.cr index c264d56..61f9589 100644 --- a/src/spectator/expectations/value_expectation_partial.cr +++ b/src/spectator/expectations/value_expectation_partial.cr @@ -1,7 +1,7 @@ require "./expectation_partial" module Spectator::Expectations - class ValueExpectationPartial(ActualType) < ExpectationPartial + struct ValueExpectationPartial(ActualType) < ExpectationPartial getter actual protected def initialize(label : String, @actual : ActualType) diff --git a/src/spectator/matchers/equality_matcher.cr b/src/spectator/matchers/equality_matcher.cr index ad9562b..cc7aaf2 100644 --- a/src/spectator/matchers/equality_matcher.cr +++ b/src/spectator/matchers/equality_matcher.cr @@ -1,7 +1,7 @@ require "./value_matcher" module Spectator::Matchers - class EqualityMatcher(ExpectedType) < ValueMatcher(ExpectedType) + struct EqualityMatcher(ExpectedType) < ValueMatcher(ExpectedType) def match?(partial : Expectations::ValueExpectationPartial(ActualType)) : Bool forall ActualType partial.actual == expected end diff --git a/src/spectator/matchers/matcher.cr b/src/spectator/matchers/matcher.cr index dae2655..84a8552 100644 --- a/src/spectator/matchers/matcher.cr +++ b/src/spectator/matchers/matcher.cr @@ -1,5 +1,5 @@ module Spectator::Matchers - abstract class Matcher + abstract struct Matcher private getter label : String private def initialize(@label) diff --git a/src/spectator/matchers/value_matcher.cr b/src/spectator/matchers/value_matcher.cr index 653dcdc..7b22a29 100644 --- a/src/spectator/matchers/value_matcher.cr +++ b/src/spectator/matchers/value_matcher.cr @@ -1,7 +1,7 @@ require "./matcher" module Spectator::Matchers - abstract class ValueMatcher(ExpectedType) < Matcher + abstract struct ValueMatcher(ExpectedType) < Matcher private getter expected def initialize(label : String, @expected : ExpectedType)