Skip to content

Commit 01cfa62

Browse files
committed
Address review comments
1 parent 7aec315 commit 01cfa62

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/lib/libstrings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ addToLibrary({
4444
return UTF8Decoder.decode(heapOrArray.buffer ? {{{ getUnsharedTextDecoderView('heapOrArray', 'idx', 'endPtr') }}} : new Uint8Array(heapOrArray.slice(idx, endPtr)));
4545
#else // TEXTDECODER == 2
4646
#if TEXTDECODER
47+
// When using conditional TextDecoder, skip it for short strings as the overhead of the native call is not worth it.
4748
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
4849
return UTF8Decoder.decode({{{ getUnsharedTextDecoderView('heapOrArray', 'idx', 'endPtr') }}});
4950
}

test/test_core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def decorated(self, *args, **kwargs):
335335
return outer_decorator
336336

337337

338-
def maybe_with_textdecoder(f):
338+
def with_both_text_decoder(f):
339339
assert callable(f)
340340

341341
@wraps(f)
@@ -5662,39 +5662,39 @@ def test_utime(self):
56625662
def test_futimens(self):
56635663
self.do_runf('utime/test_futimens.c', 'success')
56645664

5665-
@maybe_with_textdecoder
5665+
@with_both_text_decoder
56665666
def test_utf(self):
56675667
self.set_setting('EXPORTED_RUNTIME_METHODS', ['getValue', 'setValue', 'UTF8ToString', 'stringToUTF8OnStack'])
56685668
self.do_core_test('test_utf.c')
56695669

5670-
@maybe_with_textdecoder
5670+
@with_both_text_decoder
56715671
def test_utf32(self):
56725672
self.do_runf('utf32.cpp', 'OK (long).\n')
56735673

5674-
@maybe_with_textdecoder
5674+
@with_both_text_decoder
56755675
@no_sanitize('requires libc to be built with -fshort-char')
56765676
def test_utf32_short_wchar(self):
56775677
if '-flto' in self.emcc_args or '-flto=thin' in self.emcc_args:
56785678
self.skipTest('-fshort-wchar is not compatible with LTO (libraries would need rebuilting)')
56795679
self.do_runf('utf32.cpp', 'OK (short).\n', emcc_args=['-fshort-wchar'])
56805680

5681-
@maybe_with_textdecoder
5681+
@with_both_text_decoder
56825682
@crossplatform
56835683
def test_utf16(self):
56845684
self.do_runf('core/test_utf16.cpp', 'OK.')
56855685

5686-
@maybe_with_textdecoder
5686+
@with_both_text_decoder
56875687
def test_utf8(self):
56885688
self.do_runf('core/test_utf8.c', 'OK.')
56895689

5690-
@maybe_with_textdecoder
5690+
@with_both_text_decoder
56915691
@also_with_wasm_bigint
56925692
def test_utf8_bench(self):
56935693
self.emcc_args += ['--embed-file', test_file('utf8_corpus.txt') + '@/utf8_corpus.txt']
56945694
self.do_runf('benchmark/benchmark_utf8.c', 'OK.')
56955695

56965696
# Test that invalid character in UTF8 does not cause decoding to crash.
5697-
@maybe_with_textdecoder
5697+
@with_both_text_decoder
56985698
@also_with_minimal_runtime
56995699
def test_utf8_invalid(self):
57005700
self.do_runf('test_utf8_invalid.c', 'OK.')

0 commit comments

Comments
 (0)