Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 70aef77

Browse files
authoredMar 8, 2021
fix: Remove unused std string null checks and unify __gt overload (#1682)
1 parent b192a49 commit 70aef77

14 files changed

+2097
-2561
lines changed
 

‎std/assembly/string.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ import { Array } from "./array";
8080
}
8181

8282
@operator("+") private static __concat(left: String, right: String): String {
83-
return select<String>(left, changetype<String>("null"), left !== null).concat(right);
83+
return left.concat(right);
8484
}
8585

8686
concat(other: String): String {
87-
if (other === null) other = changetype<String>("null");
8887
var thisSize: isize = this.length << 1;
8988
var otherSize: isize = other.length << 1;
9089
var outSize: usize = thisSize + otherSize;
@@ -96,7 +95,6 @@ import { Array } from "./array";
9695
}
9796

9897
endsWith(search: String, end: i32 = String.MAX_LENGTH): bool {
99-
if (search === null) return false;
10098
end = min(max(end, 0), this.length);
10199
var searchLength = <isize>search.length;
102100
var searchStart = <isize>end - searchLength;
@@ -124,8 +122,8 @@ import { Array } from "./array";
124122
return !this.__eq(left, right);
125123
}
126124

127-
@operator(">") private static __gt(left: String | null, right: String | null): bool {
128-
if (left === right || left === null || right === null) return false;
125+
@operator(">") private static __gt(left: String, right: String): bool {
126+
if (left === right) return false;
129127
var leftLength = left.length;
130128
if (!leftLength) return false;
131129
var rightLength = right.length;
@@ -140,7 +138,7 @@ import { Array } from "./array";
140138
}
141139

142140
@operator("<") private static __lt(left: String, right: String): bool {
143-
if (left === right || left === null || right === null) return false;
141+
if (left === right) return false;
144142
var rightLength = right.length;
145143
if (!rightLength) return false;
146144
var leftLength = left.length;
@@ -196,7 +194,6 @@ import { Array } from "./array";
196194
}
197195

198196
startsWith(search: String, start: i32 = 0): bool {
199-
if (search === null) search = changetype<String>("null");
200197
var len = <isize>this.length;
201198
var searchStart = min(max(<isize>start, 0), len);
202199
var searchLength = <isize>search.length;

‎tests/compiler/std/array-access.optimized.wat

+58-76
Original file line numberDiff line numberDiff line change
@@ -13,88 +13,18 @@
1313
(data (i32.const 1160) "\01\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y")
1414
(data (i32.const 1276) "\1c")
1515
(data (i32.const 1288) "\01")
16-
(data (i32.const 1308) "\1c")
17-
(data (i32.const 1320) "\01\00\00\00\08\00\00\00n\00u\00l\00l")
18-
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 17724))
16+
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 17692))
1917
(export "memory" (memory $0))
2018
(export "i32ArrayArrayElementAccess" (func $export:std/array-access/i32ArrayArrayElementAccess))
2119
(export "stringArrayPropertyAccess" (func $export:std/array-access/stringArrayPropertyAccess))
2220
(export "stringArrayMethodCall" (func $export:std/array-access/stringArrayMethodCall))
2321
(export "stringArrayArrayPropertyAccess" (func $export:std/array-access/stringArrayArrayPropertyAccess))
2422
(export "stringArrayArrayMethodCall" (func $export:std/array-access/stringArrayArrayMethodCall))
25-
(func $~stack_check
26-
global.get $~lib/memory/__stack_pointer
27-
i32.const 1340
28-
i32.lt_s
29-
if
30-
i32.const 17744
31-
i32.const 17792
32-
i32.const 1
33-
i32.const 1
34-
call $~lib/builtins/abort
35-
unreachable
36-
end
37-
)
38-
(func $~lib/array/Array<~lib/array/Array<i32>>#__get (param $0 i32) (param $1 i32) (result i32)
39-
global.get $~lib/memory/__stack_pointer
40-
i32.const 4
41-
i32.sub
42-
global.set $~lib/memory/__stack_pointer
43-
call $~stack_check
44-
global.get $~lib/memory/__stack_pointer
45-
i32.const 0
46-
i32.store
47-
local.get $1
48-
local.get $0
49-
i32.load offset=12
50-
i32.ge_u
51-
if
52-
i32.const 1056
53-
i32.const 1120
54-
i32.const 92
55-
i32.const 42
56-
call $~lib/builtins/abort
57-
unreachable
58-
end
59-
global.get $~lib/memory/__stack_pointer
60-
local.get $0
61-
i32.load offset=4
62-
local.get $1
63-
i32.const 2
64-
i32.shl
65-
i32.add
66-
i32.load
67-
local.tee $0
68-
i32.store
69-
local.get $0
70-
i32.eqz
71-
if
72-
i32.const 1168
73-
i32.const 1120
74-
i32.const 96
75-
i32.const 40
76-
call $~lib/builtins/abort
77-
unreachable
78-
end
79-
global.get $~lib/memory/__stack_pointer
80-
i32.const 4
81-
i32.add
82-
global.set $~lib/memory/__stack_pointer
83-
local.get $0
84-
)
8523
(func $~lib/string/String#startsWith (param $0 i32) (result i32)
8624
(local $1 i32)
8725
(local $2 i32)
8826
(local $3 i32)
8927
(local $4 i32)
90-
global.get $~lib/memory/__stack_pointer
91-
i32.const 4
92-
i32.sub
93-
global.set $~lib/memory/__stack_pointer
94-
call $~stack_check
95-
global.get $~lib/memory/__stack_pointer
96-
i32.const 0
97-
i32.store
9828
i32.const 1292
9929
i32.load
10030
i32.const 1
@@ -119,10 +49,6 @@
11949
local.get $2
12050
i32.gt_s
12151
if
122-
global.get $~lib/memory/__stack_pointer
123-
i32.const 4
124-
i32.add
125-
global.set $~lib/memory/__stack_pointer
12652
i32.const 0
12753
return
12854
end
@@ -204,11 +130,67 @@
204130
end
205131
i32.const 0
206132
end
133+
i32.eqz
134+
)
135+
(func $~stack_check
136+
global.get $~lib/memory/__stack_pointer
137+
i32.const 1308
138+
i32.lt_s
139+
if
140+
i32.const 17712
141+
i32.const 17760
142+
i32.const 1
143+
i32.const 1
144+
call $~lib/builtins/abort
145+
unreachable
146+
end
147+
)
148+
(func $~lib/array/Array<~lib/array/Array<i32>>#__get (param $0 i32) (param $1 i32) (result i32)
207149
global.get $~lib/memory/__stack_pointer
208150
i32.const 4
209-
i32.add
151+
i32.sub
210152
global.set $~lib/memory/__stack_pointer
153+
call $~stack_check
154+
global.get $~lib/memory/__stack_pointer
155+
i32.const 0
156+
i32.store
157+
local.get $1
158+
local.get $0
159+
i32.load offset=12
160+
i32.ge_u
161+
if
162+
i32.const 1056
163+
i32.const 1120
164+
i32.const 92
165+
i32.const 42
166+
call $~lib/builtins/abort
167+
unreachable
168+
end
169+
global.get $~lib/memory/__stack_pointer
170+
local.get $0
171+
i32.load offset=4
172+
local.get $1
173+
i32.const 2
174+
i32.shl
175+
i32.add
176+
i32.load
177+
local.tee $0
178+
i32.store
179+
local.get $0
211180
i32.eqz
181+
if
182+
i32.const 1168
183+
i32.const 1120
184+
i32.const 96
185+
i32.const 40
186+
call $~lib/builtins/abort
187+
unreachable
188+
end
189+
global.get $~lib/memory/__stack_pointer
190+
i32.const 4
191+
i32.add
192+
global.set $~lib/memory/__stack_pointer
193+
local.get $0
212194
)
213195
(func $export:std/array-access/i32ArrayArrayElementAccess (param $0 i32) (result i32)
214196
global.get $~lib/memory/__stack_pointer

‎tests/compiler/std/array-access.untouched.wat

+50-81
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
(data (i32.const 76) ",\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00\00\00")
1212
(data (i32.const 124) "|\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
1313
(data (i32.const 252) "\1c\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
14-
(data (i32.const 284) "\1c\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\08\00\00\00n\00u\00l\00l\00\00\00\00\00")
1514
(table $0 1 funcref)
1615
(global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0))
17-
(global $~lib/memory/__data_end i32 (i32.const 316))
18-
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 16700))
19-
(global $~lib/memory/__heap_base i32 (i32.const 16700))
16+
(global $~lib/memory/__data_end i32 (i32.const 284))
17+
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 16668))
18+
(global $~lib/memory/__heap_base i32 (i32.const 16668))
2019
(export "memory" (memory $0))
2120
(export "i32ArrayArrayElementAccess" (func $export:std/array-access/i32ArrayArrayElementAccess))
2221
(export "stringArrayPropertyAccess" (func $export:std/array-access/stringArrayPropertyAccess))
@@ -164,13 +163,58 @@
164163
end
165164
i32.const 0
166165
)
166+
(func $~lib/string/String#startsWith (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
167+
(local $3 i32)
168+
(local $4 i32)
169+
(local $5 i32)
170+
(local $6 i32)
171+
(local $7 i32)
172+
local.get $0
173+
call $~lib/string/String#get:length
174+
local.set $3
175+
local.get $2
176+
local.tee $4
177+
i32.const 0
178+
local.tee $5
179+
local.get $4
180+
local.get $5
181+
i32.gt_s
182+
select
183+
local.tee $5
184+
local.get $3
185+
local.tee $4
186+
local.get $5
187+
local.get $4
188+
i32.lt_s
189+
select
190+
local.set $6
191+
local.get $1
192+
call $~lib/string/String#get:length
193+
local.set $7
194+
local.get $7
195+
local.get $6
196+
i32.add
197+
local.get $3
198+
i32.gt_s
199+
if
200+
i32.const 0
201+
return
202+
end
203+
local.get $0
204+
local.get $6
205+
local.get $1
206+
i32.const 0
207+
local.get $7
208+
call $~lib/util/string/compareImpl
209+
i32.eqz
210+
)
167211
(func $~stack_check
168212
global.get $~lib/memory/__stack_pointer
169213
global.get $~lib/memory/__data_end
170214
i32.lt_s
171215
if
172-
i32.const 16720
173-
i32.const 16768
216+
i32.const 16688
217+
i32.const 16736
174218
i32.const 1
175219
i32.const 1
176220
call $~lib/builtins/abort
@@ -451,81 +495,6 @@
451495
global.set $~lib/memory/__stack_pointer
452496
local.get $3
453497
)
454-
(func $~lib/string/String#startsWith (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
455-
(local $3 i32)
456-
(local $4 i32)
457-
(local $5 i32)
458-
(local $6 i32)
459-
(local $7 i32)
460-
(local $8 i32)
461-
global.get $~lib/memory/__stack_pointer
462-
i32.const 4
463-
i32.sub
464-
global.set $~lib/memory/__stack_pointer
465-
call $~stack_check
466-
global.get $~lib/memory/__stack_pointer
467-
i32.const 0
468-
i32.store
469-
local.get $1
470-
i32.const 0
471-
i32.eq
472-
if
473-
global.get $~lib/memory/__stack_pointer
474-
i32.const 304
475-
local.tee $1
476-
i32.store
477-
end
478-
local.get $0
479-
call $~lib/string/String#get:length
480-
local.set $3
481-
local.get $2
482-
local.tee $4
483-
i32.const 0
484-
local.tee $5
485-
local.get $4
486-
local.get $5
487-
i32.gt_s
488-
select
489-
local.tee $5
490-
local.get $3
491-
local.tee $4
492-
local.get $5
493-
local.get $4
494-
i32.lt_s
495-
select
496-
local.set $6
497-
local.get $1
498-
call $~lib/string/String#get:length
499-
local.set $7
500-
local.get $7
501-
local.get $6
502-
i32.add
503-
local.get $3
504-
i32.gt_s
505-
if
506-
i32.const 0
507-
local.set $8
508-
global.get $~lib/memory/__stack_pointer
509-
i32.const 4
510-
i32.add
511-
global.set $~lib/memory/__stack_pointer
512-
local.get $8
513-
return
514-
end
515-
local.get $0
516-
local.get $6
517-
local.get $1
518-
i32.const 0
519-
local.get $7
520-
call $~lib/util/string/compareImpl
521-
i32.eqz
522-
local.set $8
523-
global.get $~lib/memory/__stack_pointer
524-
i32.const 4
525-
i32.add
526-
global.set $~lib/memory/__stack_pointer
527-
local.get $8
528-
)
529498
(func $~lib/array/Array<~lib/array/Array<~lib/string/String>>#__get (param $0 i32) (param $1 i32) (result i32)
530499
(local $2 i32)
531500
(local $3 i32)
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.