Actions
Feature #13355
closed[PATCH] compile.c: optimize literal String range in case/when dispatch
Status:
Closed
Assignee:
-
Target version:
-
Description
This seems obvious, and manages to pass existing tests.
Earlier, I found myself writing code like:
case RUBY_VERSION
when '2.0.0',
'2.1.0'..'2.1.9',
'2.2.0'..'2.2.6',
'2.3.0'..'2.3.3',
'2.4.0'
# install workaround
else
puts "good!"
end
And figured other people might write similar code somewhere.
This is similar in spirit to opt_case_dispatch as the literal
Range here is guaranteed to be immutable when used for
checkmatch.
Normal range literals with non-frozen strings are actually
mutable, as Range#begin and Range#end exposes the strings to
modification. So those Range objects cannot be frozen without
breaking compatibility, but Ranges in case/when dispatch can be
frozen at compile time.
- compile.c (iseq_peephole_optimize): persistent Range creation
when String literals are used as beginning and end of range
when used for case/when dispatch.
Files
Actions
Like0
Like0Like0Like0Like0