|
50 | 50 | (global $text_converters_available (mut i32) (i32.const 0)) |
51 | 51 | (global $string_builtins_available (mut i32) (i32.const 0)) |
52 | 52 |
|
| 53 | + (global $utf16_buffer_size i32 (i32.const 32768)) |
| 54 | + (global $buffer (mut (ref $wstring)) |
| 55 | + (array.new $wstring (i32.const 0) (i32.const 0))) |
| 56 | + |
53 | 57 | (start $init) |
54 | 58 |
|
55 | 59 | (func $init |
|
74 | 78 | (i32.const 0) (i32.const 1)) |
75 | 79 | (call $fromCharCodeArray |
76 | 80 | (array.new_fixed $wstring 1 (i32.const 1)) |
77 | | - (i32.const 0) (i32.const 1)))))) |
| 81 | + (i32.const 0) (i32.const 1))))) |
| 82 | + (if (i32.eqz (global.get $text_converters_available)) |
| 83 | + (then |
| 84 | + (if (global.get $string_builtins_available) |
| 85 | + (then |
| 86 | + (global.set $buffer |
| 87 | + (array.new $wstring (i32.const 0) |
| 88 | + (global.get $utf16_buffer_size)))))))) |
78 | 89 |
|
79 | 90 | (func (export "jsstring_compare") |
80 | 91 | (param $s anyref) (param $s' anyref) (result i32) |
|
87 | 98 |
|
88 | 99 | (export "jsstring_hash" (func $hash_string)) |
89 | 100 |
|
90 | | - (func $is_ascii |
91 | | - (param $s (ref $string)) (param $i i32) (param $end i32) (result i32) |
92 | | - (loop $loop |
93 | | - (if (i32.eq (local.get $i) (local.get $end)) |
94 | | - (then (return (i32.const 1)))) |
95 | | - (if (i32.gt_u (array.get_u $string (local.get $s) (local.get $i)) |
96 | | - (i32.const 127)) |
97 | | - (then (return (i32.const 0)))) |
98 | | - (local.set $i (i32.add (local.get $i) (i32.const 1))) |
99 | | - (br $loop))) |
100 | | - |
101 | 101 | ;; Used by package zarith_stubs_js |
102 | 102 | (func $jsstring_of_substring (export "jsstring_of_substring") |
103 | 103 | (param $s (ref $string)) (param $pos i32) (param $len i32) |
104 | 104 | (result anyref) |
105 | | - (local $i i32) (local $ws (ref $wstring)) |
| 105 | + (local $i i32) (local $c i32) |
106 | 106 | (if (global.get $text_converters_available) |
107 | 107 | (then |
108 | 108 | (return |
109 | 109 | (any.convert_extern |
110 | 110 | (call $decodeStringFromUTF8Array (local.get $s) |
111 | 111 | (local.get $pos) |
112 | 112 | (i32.add (local.get $pos) (local.get $len))))))) |
113 | | - (if (i32.and (global.get $string_builtins_available) |
114 | | - (call $is_ascii |
115 | | - (local.get $s) (local.get $pos) |
116 | | - (i32.add (local.get $pos) (local.get $len)))) |
| 113 | + (if $continue |
| 114 | + (i32.and (global.get $string_builtins_available) |
| 115 | + (i32.le_u (local.get $len) (global.get $utf16_buffer_size))) |
117 | 116 | (then |
118 | | - (local.set $ws (array.new $wstring (i32.const 0) (local.get $len))) |
119 | 117 | (loop $loop |
120 | 118 | (if (i32.lt_u (local.get $i) (local.get $len)) |
121 | 119 | (then |
122 | | - (array.set $wstring (local.get $ws) (local.get $i) |
| 120 | + (local.set $c |
123 | 121 | (array.get $string (local.get $s) |
124 | 122 | (i32.add (local.get $pos) (local.get $i)))) |
| 123 | + (br_if $continue |
| 124 | + (i32.ge_u (local.get $c) (i32.const 128))) |
| 125 | + (array.set $wstring (global.get $buffer) (local.get $i) |
| 126 | + (local.get $c)) |
125 | 127 | (local.set $i (i32.add (local.get $i) (i32.const 1))) |
126 | | - |
127 | 128 | (br $loop)))) |
128 | 129 | (return |
129 | 130 | (any.convert_extern |
130 | | - (call $fromCharCodeArray (local.get $ws) |
| 131 | + (call $fromCharCodeArray (global.get $buffer) |
131 | 132 | (i32.const 0) (local.get $len)))))) |
132 | 133 | (return_call $jsstring_of_substring_fallback |
133 | 134 | (local.get $s) (local.get $pos) (local.get $len))) |
|
0 commit comments