Repository navigation
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…pe error names Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Mirror StringSupport.trTransHelper: a 256-entry array for low codepoints and an IntHash above that, decode only non-ASCII characters, and copy unchanged runs only once a replacement is found so a no-op returns nil without copying. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…and errors Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The lambda overload of RubyHash#visitAll counts entries up front and raises ConcurrencyError when a key's #to_str deletes another entry. Use the state-passing overload, which skips removed entries like Hash#each and MRI's rb_hash_foreach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Pushed cf9af4a to fix a crash found while comparing against CRuby 4.1. If a key's pairs = {}
key = Object.new
key.define_singleton_method(:to_str) { pairs.delete("b"); "a" }
pairs[key] = "x"
pairs["b"] = "y"
"ab".tr(pairs) # CRuby: "xb", JRuby before: ConcurrencyErrorThe lambda overload of Not changed: CRuby raises 🤖 Generated with Claude Code |
Part of #9746.
Adds the single-Hash form of
String#trandString#tr!from Ruby 4.1 (Feature #22238):Keys must be a single character; values may be any string (including empty, which deletes). Replacement is a single pass, so replaced text is never rescanned.
tr!returnsnilwhen nothing changed.Implementation
RubyString#trTransPairs, modelled on CRuby'str_trans_pairs:Check_Type(Hash), broken string, frozen, then empty receiver/hash returnsnil.checkMultiStris a port ofrb_enc_check_multi_str. It folds each key and value into one negotiated encoding or raisesEncoding::CompatibilityError; the result is tagged with it.IntHash, asStringSupport.trTransHelperdoes. ASCII bytes in ASCII-compatible encodings skip decoding.nilwithout copying.The four commits are kept separate so the port, the review fixes, the table rewrite and the specs can be diffed individually; happy to squash.
Not done / differences from CRuby
@CRubyannotation not used sinceorg.jruby.anno.CRubyis not onruby-4.1yet;// MRI:comments follow the file's current convention.Testing
hash formexamples already inspec/ruby/core/string/tr_spec.rb(ruby_version_is "4.1") pass.FrozenErrorand theTypeErrormessages. They also pass on CRuby 4.1.0-dev (44/44).tr_spec.rb/tr_s_spec.rb: only the existing tagged "c1-c1" examples fail.tr!cases produced identical output.spec:ruby:fastbaseline diff.🤖 Generated with Claude Code