[ji] RubyString implements CharSequence #5180
Conversation
other way to avoid conversion (when seeing |
I have no issues with the actual code changes here. I do worry about the length method changing signature but it does seem unlikely someone would use that rather than "strLength", and that's backward-compatible until everyone can be assured the "IRubyObject length()" is gone. We haven't really had a chance to verify this with any third-party extensions, though. In general, I like this change at 9.2. I think we need to be more bold these days. |
posting some micro-benchmarking numbers :
... instead of testing 'real-world' the case tries to do |
found this🖌️ at https://github.com/jruby/jruby/pull/3937/files#diff-2f8f0aefd8a8637512ce6c017da265b9
knew I saw a draft of this somewhere but did not find it until I checked some old PRs :)
... there's an opportunity here to have
RubyString implements CharSequence
this is expected to fit nicely esp. will avoid conversions on logging libraries e.g. log4j2
(so one doesn't need to do an if check:
logger.debug('foo') if logger.isDebugEnabled
)but its a breaking change in 2 ways :
RubyString#length
needs to be changed (to return int) -> not expected to be used muchjava.lang.CharSequence
by JI will no longer conver to a java stringboth seem acceptable for a major release such as 9.2 (we sure can not do this in a minor one)