Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Aug 27, 2023
1 parent 26a2e15 commit 450a989
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ FixedPointMathLibTest:testSqrtHashedSingle() (gas: 53086)
FixedPointMathLibTest:testZeroFloorSub(uint256,uint256) (runs: 256, μ: 548, ~: 518)
FixedPointMathLibTest:testZeroFloorSubCasted(uint32,uint32,uint256) (runs: 256, μ: 905, ~: 945)
FixedPointMathLibTest:test__codesize() (gas: 19246)
JSONParserLibTest:testDecodeInvalidStringReverts() (gas: 56449)
JSONParserLibTest:testDecodeString() (gas: 51270)
JSONParserLibTest:testDecodeInvalidStringReverts() (gas: 56186)
JSONParserLibTest:testDecodeString() (gas: 50960)
JSONParserLibTest:testParseEmptyArrays() (gas: 629602)
JSONParserLibTest:testParseEmptyObjects() (gas: 630563)
JSONParserLibTest:testParseGas() (gas: 140700)
Expand All @@ -391,7 +391,7 @@ JSONParserLibTest:testParseSimpleUintArray() (gas: 1300549)
JSONParserLibTest:testParseSpecials() (gas: 301555)
JSONParserLibTest:testParseString() (gas: 680874)
JSONParserLibTest:testParseUint() (gas: 25985)
JSONParserLibTest:test__codesize() (gas: 30244)
JSONParserLibTest:test__codesize() (gas: 30233)
LibBitTest:testAnd() (gas: 185677)
LibBitTest:testAnd(bool,bool) (runs: 256, μ: 668, ~: 667)
LibBitTest:testAutoClean(uint256,uint256) (runs: 256, μ: 446, ~: 446)
Expand Down
54 changes: 29 additions & 25 deletions src/utils/JSONParserLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -409,34 +409,38 @@ library JSONParserLib {
for { let curr := add(s, 0x21) } iszero(eq(curr, end)) {} {
let c := chr(curr)
curr := add(curr, 1)
if eq(c, 34) { fail() } // '"'.
// Not '\\'.
if iszero(eq(c, 92)) {
mstore8(out, c)
out := add(out, 1)
continue
}
if eq(curr, end) { fail() }
let escape := chr(curr)
curr := add(curr, 1)
// '"', '/', '\\'.
if and(shr(sub(escape, 34), 0x400000000002001), 1) {
mstore8(out, escape)
out := add(out, 1)
continue
}
// `{'b':'\b', 'f':'\f', 'n':'\n', 'r':'\r', 't':'\t'}`.
let cc := byte(sub(escape, 85), 0x080000000c000000000000000a0000000d0009)
if cc {
mstore8(out, cc)
out := add(out, 1)
continue
// Not '"'.
if iszero(eq(c, 34)) {
mstore8(out, c)
out := add(out, 1)
continue
}
curr := end
}
// 'u'.
if eq(escape, 117) {
escape, curr := decodeUnicodeCodePoint(curr, end)
out := appendCodePointAsUTF8(out, escape)
continue
if iszero(eq(curr, end)) {
let escape := chr(curr)
curr := add(curr, 1)
// '"', '/', '\\'.
if and(shr(sub(escape, 34), 0x400000000002001), 1) {
mstore8(out, escape)
out := add(out, 1)
continue
}
// 'u'.
if eq(escape, 117) {
escape, curr := decodeUnicodeCodePoint(curr, end)
out := appendCodePointAsUTF8(out, escape)
continue
}
// `{'b':'\b', 'f':'\f', 'n':'\n', 'r':'\r', 't':'\t'}`.
escape := byte(sub(escape, 85), 0x080000000c000000000000000a0000000d0009)
if escape {
mstore8(out, escape)
out := add(out, 1)
continue
}
}
fail()
break
Expand Down

0 comments on commit 450a989

Please sign in to comment.