improve tonumber/0 performance by parsing input as number literal

Previously, the tonumber/0 filter parses the input as JSON values, but
this is less-performant on large non-number strings. Parsing the input
string as number literal fixes the performance issue. Also, this fix
changes the filter to reject numbers with white spaces.
This commit is contained in:
itchyny authored and GitHub committed 2024-03-01 16:33:17 +01:00
1 parent 913b26469f
commit ce0e788ce2
2 files changed
+19 -6

No files matched your search

+2 -2
View File
@@ -2000,8 +2000,8 @@ null
2
.[] |= try tonumber
["1", "2a", "3", 4]
[1, 3, 4]
["1", "2a", "3", " 4 ", "5.67", ".89", "-876", "+5.43", 21]
[1, 3, 5.67, 0.89, -876, 5.43, 21]
# Also 1859, but from 2073
any(keys[]|tostring?;true)