@ 261102.1

261025.1 · 864d769d888e49621849c8ad616d794f099e713f

Implement ascii_downcase and ascii_upcase in C (#3689)

Both were defined as explode | map(...) | implode, which took 4 seconds on a 10 MB string, about 90 times as long as parsing it.

Change the case of A-Z or a-z a byte at a time in C, copying multibyte UTF-8 sequences unchanged, so the output stays the same and the 10 MB case now takes about 60 ms including parsing. On a non-string input the error now names the function, "ascii_downcase input must be a string", instead of "explode input must be a string".

reading declarations

Changes to src/builtin.jq. All files

src/builtin.jq

@@ -184,12 +184,6 @@ def repeat(exp):          exp, _repeat;      _repeat; def inputs: try repeat(input) catch if .=="break" then empty else error end;-# like ruby's downcase - only characters A to Z are affected-def ascii_downcase:-  explode | map( if 65 <= . and . <= 90 then . + 32  else . end) | implode;-# like ruby's upcase - only characters a to z are affected-def ascii_upcase:-  explode | map( if 97 <= . and . <= 122 then . - 32  else . end) | implode;  # Streaming utilities def truncate_stream(stream):