Skip to content

Replace bindings using a single name lookup - #285

Open
OskarEichler wants to merge 1 commit into
trailblazer:masterfrom
OskarEichler:codex/map-replacement
Open

Replace bindings using a single name lookup#285
OskarEichler wants to merge 1 commit into
trailblazer:masterfrom
OskarEichler:codex/map-replacement

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Find the matching index directly, avoiding a second equality-based scan. Custom binding equality can currently make that second scan replace a different earlier binding.

Reproduction

require 'representable/json/hash'
type=Struct.new(:name) { def ==(_); true; end }
a=type.new('a'); old=type.new('b'); replacement=type.new('b')
map=Representable::Binding::Map.new([a,old]); map << replacement
p [map.first.equal?(a), map.last.equal?(replacement)]
# [false,false] before; [true,true] after

Verification

  • Existing master suite on this isolated branch: 545 tests / 701 assertions, zero failures/errors, three existing skips on Ruby 3.2.11. Ruby 4.0.6 retains the same eight legacy inspection-format failures, zero errors and three skips. Existing tests/expectations are unchanged.
  • 300 focused checks on Ruby 3.2.11/4.0.6 for this change. XML first-render uses a separate fresh-process check.
  • Combined release-based verification with other focused fixes and attributed Use Setter in OverwriteOnNil if a :setter is defined #177/Hash value of null breaks parsing #264/Update MultiJSON usage to address deprecations #273 source backports: 544 tests / 700 assertions pass on Ruby 3.2.11, plus 4,410 focused checks and 36 boundary checks. Package retains 104 paths and unchanged compared metadata. All 36 runtime files compile on both Rubies; no newly introduced default Lint offenses.

Isolated YJIT measurement: three alternating process pairs, each with five batches of 1,000 last-entry replacements in a 1,000-binding map. Median time 0.063231→0.036169s, zero allocations in both measured loops. No production throughput claim.

Breaking changes / limitations

Replacement remains defined by name and preserves position. Append/replacement return values remain unchanged; misleading custom equality no longer redirects replacement.

No new/modified checked-in tests. Ruby 2.4–3.1, JRuby, Windows and Linux were not executed locally. Ruby >=2.4 and runtime dependency ranges remain unchanged. External test tooling supplies a legacy MiniTest alias and ruby-prof 1.7.x; no assertions were changed. No production verification is claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant