jsonparse: A bunch of performance improvements

Turrns out JSON::XS had some pretty good ideas that I could borrow.
This commit is contained in:
Yorhel 2025-01-31 16:35:47 +01:00
parent ca8d1b72be
commit ebe84167e7
5 changed files with 144 additions and 111 deletions

View file

@ -49,6 +49,7 @@ my @error = (
'{"":1,}',
'{,}',
'{"":1,"":2}',
'{"ë":1,"ë":1}',
);
for my $s (@error) {
ok !eval { json_parse($s); 1 };
@ -70,10 +71,10 @@ sub str($in, $exp) {
utf8::encode(my $str = $in);
my $out = json_parse($in);
is $out, $exp, $str;
ok utf8::is_utf8($out);
ok utf8::is_utf8($out) || $out =~ /^[\x00-\x7f]*$/;
$out = json_parse($str, utf8 => 1);
is $out, $exp, $str;
ok utf8::is_utf8($out);
ok utf8::is_utf8($out) || $out =~ /^[\x00-\x7f]*$/;
}
str '""', '';
str '"hello, world"', 'hello, world';