Skip to content

Commit

Permalink
Fix issue with constraint allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Jan 10, 2025
1 parent 3589dea commit 8ff2b63
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ jobs:
bundler-args: --without development
- name: Quickdraw tests
run: bundle exec qt -t 1 "./test/**/*.test.rb"
- name: Test allocations
run: bundle exec ./allocations_test.rb
rubocop:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.3']
ruby-version: ["3.4"]
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0
3.4.1
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.4.1
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ gem "quickdraw", git: "https://github.com/joeldrapper/quickdraw.git"
gem "benchmark-ips"

group :development do
gem "solargraph", platform: :ruby
gem "rubocop", platform: :ruby
gem "ruby-lsp", platform: :ruby
gem "simplecov", platform: :ruby
Expand Down
1 change: 1 addition & 0 deletions allocations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def count_allocations
def count_warm_allocations(&)
count_allocations(&)
count_allocations(&)
count_allocations(&)
end

def assert_allocations(type, thing)
Expand Down
9 changes: 7 additions & 2 deletions lib/literal/types/constraint_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ def ===(value)
i += 1
end

result = true

@property_constraints.each do |a, t|
return false unless t === value.public_send(a)
# We intentionally don’t return early here becuase it triggers an allocation.
if result && !(t === value.public_send(a))
result = false
end
rescue NoMethodError => e
raise unless e.name == a && e.receiver == value
return false
end

true
result
end

def >=(other)
Expand Down

0 comments on commit 8ff2b63

Please sign in to comment.