mirror of
https://github.com/ruby/ruby.git
synced 2026-08-03 11:18:06 +08:00
Get rid of the CFUNC overhead in String#ascii_only? and #valid_encoding?. Define them as leaf Primitive.cexpr! builtins in a new string.rb, following the pattern of numeric.rb. This makes them 1.2x-1.4x faster across the interpreter, YJIT, and ZJIT. Move ZJIT's cfunc annotation for String#ascii_only? to annotate_builtin!, and add one for String#valid_encoding?. Fix CI for builtin String#ascii_only?
8 lines
203 B
YAML
8 lines
203 B
YAML
prelude: |
|
|
utf8 = "héllo wörld 晦"
|
|
broken = "\xff\xfe".dup.force_encoding("UTF-8")
|
|
benchmark:
|
|
valid_enc_true: utf8.valid_encoding?
|
|
valid_enc_false: broken.valid_encoding?
|
|
loop_count: 20000000
|