diff --git a/std/assembly/string.ts b/std/assembly/string.ts index b44a5fc9..9cb396a4 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -63,9 +63,7 @@ export class String { changetype(this) + ((pos + 1) << 1), HEADER_SIZE ); - if (second < 0xDC00 || second > 0xDFFF) { - return first; - } + if (second < 0xDC00 || second > 0xDFFF) return first; return ((first - 0xD800) << 10) + (second - 0xDC00) + 0x10000; } @@ -83,16 +81,19 @@ export class String { var outLen: usize = thisLen + otherLen; if (outLen == 0) return EMPTY; var out = allocate(outLen); + move_memory( changetype(out) + HEADER_SIZE, changetype(this) + HEADER_SIZE, thisLen << 1 ); + move_memory( changetype(out) + HEADER_SIZE + (thisLen << 1), changetype(other) + HEADER_SIZE, otherLen << 1 ); + return out; } @@ -102,9 +103,7 @@ export class String { var end: isize = min(max(endPosition, 0), this.length); var searchLength: isize = searchString.length; var start: isize = end - searchLength; - if (start < 0) { - return false; - } + if (start < 0) return false; return !compare_memory( changetype(this) + HEADER_SIZE + (start << 1), changetype(searchString) + HEADER_SIZE, @@ -116,8 +115,10 @@ export class String { private static __eq(left: String, right: String): bool { if (left === null) return right === null; else if (right === null) return false; + var leftLength = left.length; if (leftLength != right.length) return false; + return !compare_memory( changetype(left) + HEADER_SIZE, changetype(right) + HEADER_SIZE, @@ -132,9 +133,7 @@ export class String { @operator(">") private static __gt(left: String, right: String): bool { - if (!changetype(left) || !changetype(right)) { - return false; - } + if (left === null || right === null) return false; var leftLength = left.length; var rightLength = right.length; @@ -152,9 +151,8 @@ export class String { @operator(">=") private static __gte(left: String, right: String): bool { - if (!changetype(left) || !changetype(right)) { - return false; - } + if (left === null) return right === null; + else if (right === null) return false; var leftLength = left.length; var rightLength = right.length; @@ -172,9 +170,7 @@ export class String { @operator("<") private static __lt(left: String, right: String): bool { - if (!changetype(left) || !changetype(right)) { - return false; - } + if (left === null || right === null) return false; var leftLength = left.length; var rightLength = right.length; @@ -192,9 +188,8 @@ export class String { @operator("<=") private static __lte(left: String, right: String): bool { - if (!changetype(left) || !changetype(right)) { - return false; - } + if (left === null) return right === null; + else if (right === null) return false; var leftLength = left.length; var rightLength = right.length; diff --git a/tests/compiler/std/array-access.optimized.wat b/tests/compiler/std/array-access.optimized.wat index d62e2165..c206cc2a 100644 --- a/tests/compiler/std/array-access.optimized.wat +++ b/tests/compiler/std/array-access.optimized.wat @@ -125,7 +125,7 @@ (call $abort (i32.const 0) (i32.const 8) - (i32.const 239) + (i32.const 234) (i32.const 4) ) (unreachable) diff --git a/tests/compiler/std/array-access.untouched.wat b/tests/compiler/std/array-access.untouched.wat index 504d1603..5bea1087 100644 --- a/tests/compiler/std/array-access.untouched.wat +++ b/tests/compiler/std/array-access.untouched.wat @@ -195,7 +195,7 @@ (call $abort (i32.const 0) (i32.const 8) - (i32.const 239) + (i32.const 234) (i32.const 4) ) (unreachable) diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index bf88446e..9fd3b2a4 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -154,7 +154,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 239) + (i32.const 234) (i32.const 4) ) (unreachable) @@ -264,7 +264,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 100) + (i32.const 101) (i32.const 4) ) (unreachable) @@ -374,7 +374,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 218) + (i32.const 213) (i32.const 4) ) (unreachable) @@ -1085,7 +1085,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 563) + (i32.const 558) (i32.const 10) ) (unreachable) @@ -3171,7 +3171,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 79) + (i32.const 77) (i32.const 4) ) (unreachable) @@ -3394,32 +3394,29 @@ (local $2 i32) (local $3 i32) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (get_local $0) - ) - ) - (get_local $2) - (i32.eqz - (get_local $1) - ) + (get_local $0) + (if + (i32.eqz + (get_local $1) + ) + (return + (i32.const 0) ) - (i32.const 1) ) (return - (i32.const 0) + (i32.eqz + (get_local $1) + ) ) ) - (set_local $3 + (set_local $2 (i32.load (get_local $1) ) ) (if (i32.eqz - (tee_local $2 + (tee_local $3 (i32.load (get_local $0) ) @@ -3427,13 +3424,13 @@ ) (return (i32.eqz - (get_local $3) + (get_local $2) ) ) ) (if (i32.eqz - (get_local $3) + (get_local $2) ) (return (i32.const 1) @@ -3451,11 +3448,11 @@ ) (i32.shl (select - (get_local $2) (get_local $3) + (get_local $2) (i32.lt_s - (get_local $2) (get_local $3) + (get_local $2) ) ) (i32.const 1) @@ -3540,22 +3537,19 @@ (local $2 i32) (local $3 i32) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (get_local $0) - ) - ) - (get_local $2) - (i32.eqz - (get_local $1) - ) + (get_local $0) + (if + (i32.eqz + (get_local $1) + ) + (return + (i32.const 0) ) - (i32.const 1) ) (return - (i32.const 0) + (i32.eqz + (get_local $1) + ) ) ) (set_local $2 diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index d740a55a..b6c2d197 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -203,7 +203,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 239) + (i32.const 234) (i32.const 4) ) (unreachable) @@ -333,7 +333,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 100) + (i32.const 101) (i32.const 4) ) (unreachable) @@ -461,7 +461,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 218) + (i32.const 213) (i32.const 4) ) (unreachable) @@ -1263,7 +1263,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 563) + (i32.const 558) (i32.const 10) ) (unreachable) @@ -3649,7 +3649,7 @@ (call $abort (i32.const 0) (i32.const 72) - (i32.const 79) + (i32.const 77) (i32.const 4) ) (unreachable) @@ -3826,13 +3826,15 @@ (i32.and (if (result i32) (tee_local $2 - (i32.eqz + (i32.eq (get_local $0) + (i32.const 0) ) ) (get_local $2) - (i32.eqz + (i32.eq (get_local $1) + (i32.const 0) ) ) (i32.const 1) @@ -3908,62 +3910,64 @@ (local $5 i32) (local $6 i32) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (get_local $0) - ) - ) - (get_local $2) - (i32.eqz - (get_local $1) - ) - ) - (i32.const 1) - ) - (return + (i32.eq + (get_local $0) (i32.const 0) ) + (return + (i32.eq + (get_local $1) + (i32.const 0) + ) + ) + (if + (i32.eq + (get_local $1) + (i32.const 0) + ) + (return + (i32.const 0) + ) + ) ) - (set_local $3 + (set_local $2 (i32.load (get_local $0) ) ) - (set_local $4 + (set_local $3 (i32.load (get_local $1) ) ) + (if + (i32.eqz + (get_local $2) + ) + (return + (i32.eqz + (get_local $3) + ) + ) + ) (if (i32.eqz (get_local $3) ) - (return - (i32.eqz - (get_local $4) - ) - ) - ) - (if - (i32.eqz - (get_local $4) - ) (return (i32.const 1) ) ) (set_local $6 (select - (tee_local $2 - (get_local $3) + (tee_local $4 + (get_local $2) ) (tee_local $5 - (get_local $4) + (get_local $3) ) (i32.lt_s - (get_local $2) + (get_local $4) (get_local $5) ) ) @@ -3998,13 +4002,15 @@ (i32.and (if (result i32) (tee_local $2 - (i32.eqz + (i32.eq (get_local $0) + (i32.const 0) ) ) (get_local $2) - (i32.eqz + (i32.eq (get_local $1) + (i32.const 0) ) ) (i32.const 1) @@ -4080,62 +4086,64 @@ (local $5 i32) (local $6 i32) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (get_local $0) - ) - ) - (get_local $2) - (i32.eqz - (get_local $1) - ) - ) - (i32.const 1) - ) - (return + (i32.eq + (get_local $0) (i32.const 0) ) + (return + (i32.eq + (get_local $1) + (i32.const 0) + ) + ) + (if + (i32.eq + (get_local $1) + (i32.const 0) + ) + (return + (i32.const 0) + ) + ) ) - (set_local $3 + (set_local $2 (i32.load (get_local $0) ) ) - (set_local $4 + (set_local $3 (i32.load (get_local $1) ) ) - (if - (i32.eqz - (get_local $4) - ) - (return - (i32.eqz - (get_local $3) - ) - ) - ) (if (i32.eqz (get_local $3) ) + (return + (i32.eqz + (get_local $2) + ) + ) + ) + (if + (i32.eqz + (get_local $2) + ) (return (i32.const 1) ) ) (set_local $6 (select - (tee_local $2 - (get_local $3) + (tee_local $4 + (get_local $2) ) (tee_local $5 - (get_local $4) + (get_local $3) ) (i32.lt_s - (get_local $2) + (get_local $4) (get_local $5) ) )