diff --git a/std/assembly/string.ts b/std/assembly/string.ts index 0ede3ccf..70a8527a 100644 --- a/std/assembly/string.ts +++ b/std/assembly/string.ts @@ -162,17 +162,7 @@ export class String { @operator(">=") private static __gte(left: String, right: String): bool { - if (left === right) return true; - if (left === null || right === null) return false; - - var leftLength = left.length; - var rightLength = right.length; - - if (!leftLength) return !rightLength; - if (!rightLength) return true; - - var length = min(leftLength, rightLength); - return compareUnsafe(left, 0, right, 0, length) >= 0; + return !this.__lt(left, right); } @operator("<") @@ -191,17 +181,7 @@ export class String { @operator("<=") private static __lte(left: String, right: String): bool { - if (left === right) return true; - if (left === null || right === null) return false; - - var leftLength = left.length; - var rightLength = right.length; - - if (!rightLength) return !leftLength; - if (!leftLength) return true; - - var length = min(leftLength, rightLength); - return compareUnsafe(left, 0, right, 0, length) <= 0; + return !this.__gt(left, right); } @inline diff --git a/tests/compiler/number.optimized.wat b/tests/compiler/number.optimized.wat index 040f7788..4d966a72 100644 --- a/tests/compiler/number.optimized.wat +++ b/tests/compiler/number.optimized.wat @@ -2527,7 +2527,7 @@ if i32.const 0 i32.const 2072 - i32.const 269 + i32.const 249 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/number.untouched.wat b/tests/compiler/number.untouched.wat index 8e30c2c0..a23439d0 100644 --- a/tests/compiler/number.untouched.wat +++ b/tests/compiler/number.untouched.wat @@ -3534,7 +3534,7 @@ if i32.const 0 i32.const 2072 - i32.const 269 + i32.const 249 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array-access.optimized.wat b/tests/compiler/std/array-access.optimized.wat index 6218512a..e1c758af 100644 --- a/tests/compiler/std/array-access.optimized.wat +++ b/tests/compiler/std/array-access.optimized.wat @@ -113,7 +113,7 @@ if i32.const 0 i32.const 16 - i32.const 244 + i32.const 224 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array-access.untouched.wat b/tests/compiler/std/array-access.untouched.wat index b7b3b714..b45c438c 100644 --- a/tests/compiler/std/array-access.untouched.wat +++ b/tests/compiler/std/array-access.untouched.wat @@ -199,7 +199,7 @@ if i32.const 0 i32.const 16 - i32.const 244 + i32.const 224 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 6cccb13d..cc1becf9 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -6368,7 +6368,7 @@ if i32.const 0 i32.const 4056 - i32.const 269 + i32.const 249 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 95fe4b48..8dd7b014 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -11620,7 +11620,7 @@ if i32.const 0 i32.const 4056 - i32.const 269 + i32.const 249 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/string-utf8.optimized.wat b/tests/compiler/std/string-utf8.optimized.wat index ed7e6cc5..0c0d2622 100644 --- a/tests/compiler/std/string-utf8.optimized.wat +++ b/tests/compiler/std/string-utf8.optimized.wat @@ -1575,7 +1575,7 @@ if i32.const 0 i32.const 72 - i32.const 527 + i32.const 507 i32.const 8 call $~lib/env/abort unreachable @@ -1622,7 +1622,7 @@ if i32.const 0 i32.const 72 - i32.const 531 + i32.const 511 i32.const 8 call $~lib/env/abort unreachable @@ -1695,7 +1695,7 @@ if i32.const 0 i32.const 72 - i32.const 543 + i32.const 523 i32.const 8 call $~lib/env/abort unreachable @@ -1748,7 +1748,7 @@ if i32.const 0 i32.const 72 - i32.const 552 + i32.const 532 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/string-utf8.untouched.wat b/tests/compiler/std/string-utf8.untouched.wat index c66caa9a..3720fe32 100644 --- a/tests/compiler/std/string-utf8.untouched.wat +++ b/tests/compiler/std/string-utf8.untouched.wat @@ -2008,7 +2008,7 @@ if i32.const 0 i32.const 72 - i32.const 527 + i32.const 507 i32.const 8 call $~lib/env/abort unreachable @@ -2062,7 +2062,7 @@ if i32.const 0 i32.const 72 - i32.const 531 + i32.const 511 i32.const 8 call $~lib/env/abort unreachable @@ -2157,7 +2157,7 @@ if i32.const 0 i32.const 72 - i32.const 543 + i32.const 523 i32.const 8 call $~lib/env/abort unreachable @@ -2220,7 +2220,7 @@ if i32.const 0 i32.const 72 - i32.const 552 + i32.const 532 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index 40e96fb5..740c747a 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -464,7 +464,7 @@ if i32.const 0 i32.const 80 - i32.const 244 + i32.const 224 i32.const 4 call $~lib/env/abort unreachable @@ -553,7 +553,7 @@ if i32.const 0 i32.const 80 - i32.const 213 + i32.const 193 i32.const 4 call $~lib/env/abort unreachable @@ -1951,7 +1951,7 @@ if i32.const 0 i32.const 80 - i32.const 360 + i32.const 340 i32.const 4 call $~lib/env/abort unreachable @@ -2061,7 +2061,7 @@ if i32.const 0 i32.const 80 - i32.const 380 + i32.const 360 i32.const 4 call $~lib/env/abort unreachable @@ -2172,7 +2172,7 @@ if i32.const 0 i32.const 80 - i32.const 229 + i32.const 209 i32.const 4 call $~lib/env/abort unreachable @@ -2626,7 +2626,7 @@ if i32.const 0 i32.const 80 - i32.const 645 + i32.const 625 i32.const 10 call $~lib/env/abort unreachable @@ -2801,62 +2801,7 @@ i32.const 0 i32.gt_s ) - (func $~lib/string/String.__gte (; 28 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - local.get $0 - local.get $1 - i32.eq - if - i32.const 1 - return - end - local.get $0 - i32.eqz - local.tee $2 - i32.eqz - if - local.get $1 - i32.eqz - local.set $2 - end - local.get $2 - if - i32.const 0 - return - end - local.get $1 - i32.load - local.set $3 - local.get $0 - i32.load - local.tee $2 - i32.eqz - if - local.get $3 - i32.eqz - return - end - local.get $3 - i32.eqz - if - i32.const 1 - return - end - local.get $0 - i32.const 0 - local.get $1 - local.get $2 - local.get $3 - local.get $2 - local.get $3 - i32.lt_s - select - call $~lib/internal/string/compareUnsafe - i32.const 0 - i32.ge_s - ) - (func $~lib/string/String.__lt (; 29 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__lt (; 28 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) local.get $0 @@ -2911,52 +2856,17 @@ i32.const 0 i32.lt_s ) + (func $~lib/string/String.__gte (; 29 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + call $~lib/string/String.__lt + i32.eqz + ) (func $~lib/string/String.__lte (; 30 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - local.get $0 i32.const 256 - i32.eq - if - i32.const 1 - return - end local.get $0 + call $~lib/string/String.__gt i32.eqz - if - i32.const 0 - return - end - i32.const 256 - i32.load - local.set $1 - local.get $0 - i32.load - local.tee $2 - i32.eqz - if - local.get $1 - i32.eqz - return - end - local.get $1 - i32.eqz - if - i32.const 1 - return - end - i32.const 256 - i32.const 0 - local.get $0 - local.get $1 - local.get $2 - local.get $1 - local.get $2 - i32.lt_s - select - call $~lib/internal/string/compareUnsafe - i32.const 0 - i32.le_s ) (func $~lib/string/String#repeat (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) @@ -2966,7 +2876,7 @@ if i32.const 0 i32.const 80 - i32.const 400 + i32.const 380 i32.const 4 call $~lib/env/abort unreachable @@ -2991,7 +2901,7 @@ if i32.const 0 i32.const 80 - i32.const 405 + i32.const 385 i32.const 6 call $~lib/env/abort unreachable @@ -3552,7 +3462,7 @@ if i32.const 0 i32.const 80 - i32.const 428 + i32.const 408 i32.const 4 call $~lib/env/abort unreachable @@ -5257,7 +5167,7 @@ if i32.const 0 i32.const 80 - i32.const 269 + i32.const 249 i32.const 4 call $~lib/env/abort unreachable diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index 16d06f04..af583098 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -546,7 +546,7 @@ if i32.const 0 i32.const 80 - i32.const 244 + i32.const 224 i32.const 4 call $~lib/env/abort unreachable @@ -695,7 +695,7 @@ if i32.const 0 i32.const 80 - i32.const 213 + i32.const 193 i32.const 4 call $~lib/env/abort unreachable @@ -2528,7 +2528,7 @@ if i32.const 0 i32.const 80 - i32.const 360 + i32.const 340 i32.const 4 call $~lib/env/abort unreachable @@ -2645,7 +2645,7 @@ if i32.const 0 i32.const 80 - i32.const 380 + i32.const 360 i32.const 4 call $~lib/env/abort unreachable @@ -2762,7 +2762,7 @@ if i32.const 0 i32.const 80 - i32.const 229 + i32.const 209 i32.const 4 call $~lib/env/abort unreachable @@ -3295,7 +3295,7 @@ if i32.const 0 i32.const 80 - i32.const 645 + i32.const 625 i32.const 10 call $~lib/env/abort unreachable @@ -3503,72 +3503,7 @@ i32.const 0 i32.gt_s ) - (func $~lib/string/String.__gte (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) - local.get $0 - local.get $1 - i32.eq - if - i32.const 1 - return - end - local.get $0 - i32.const 0 - i32.eq - local.tee $2 - if (result i32) - local.get $2 - else - local.get $1 - i32.const 0 - i32.eq - end - if - i32.const 0 - return - end - local.get $0 - i32.load - local.set $3 - local.get $1 - i32.load - local.set $4 - local.get $3 - i32.eqz - if - local.get $4 - i32.eqz - return - end - local.get $4 - i32.eqz - if - i32.const 1 - return - end - local.get $3 - local.tee $2 - local.get $4 - local.tee $5 - local.get $2 - local.get $5 - i32.lt_s - select - local.set $6 - local.get $0 - i32.const 0 - local.get $1 - i32.const 0 - local.get $6 - call $~lib/internal/string/compareUnsafe - i32.const 0 - i32.ge_s - ) - (func $~lib/string/String.__lt (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__lt (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3633,70 +3568,17 @@ i32.const 0 i32.lt_s ) + (func $~lib/string/String.__gte (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + call $~lib/string/String.__lt + i32.eqz + ) (func $~lib/string/String.__lte (; 32 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) local.get $0 local.get $1 - i32.eq - if - i32.const 1 - return - end - local.get $0 - i32.const 0 - i32.eq - local.tee $2 - if (result i32) - local.get $2 - else - local.get $1 - i32.const 0 - i32.eq - end - if - i32.const 0 - return - end - local.get $0 - i32.load - local.set $3 - local.get $1 - i32.load - local.set $4 - local.get $4 + call $~lib/string/String.__gt i32.eqz - if - local.get $3 - i32.eqz - return - end - local.get $3 - i32.eqz - if - i32.const 1 - return - end - local.get $3 - local.tee $2 - local.get $4 - local.tee $5 - local.get $2 - local.get $5 - i32.lt_s - select - local.set $6 - local.get $0 - i32.const 0 - local.get $1 - i32.const 0 - local.get $6 - call $~lib/internal/string/compareUnsafe - i32.const 0 - i32.le_s ) (func $~lib/string/String#repeat (; 33 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) @@ -3709,7 +3591,7 @@ if i32.const 0 i32.const 80 - i32.const 400 + i32.const 380 i32.const 4 call $~lib/env/abort unreachable @@ -3735,7 +3617,7 @@ if i32.const 0 i32.const 80 - i32.const 405 + i32.const 385 i32.const 6 call $~lib/env/abort unreachable @@ -4486,7 +4368,7 @@ if i32.const 0 i32.const 80 - i32.const 428 + i32.const 408 i32.const 4 call $~lib/env/abort unreachable @@ -7000,7 +6882,7 @@ if i32.const 0 i32.const 80 - i32.const 269 + i32.const 249 i32.const 4 call $~lib/env/abort unreachable