diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-12 19:01:48 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-12 19:01:48 -0700 |
commit | 7e2e2380a751d6671183016180cc25147736c1fd (patch) | |
tree | e5c5f7f08da2bcbc59b389b25d3e698931aa394e | |
parent | eb92e14f7649656e4ec50c7450bd1aa3740256da (diff) |
asmify strncpy
-rw-r--r-- | src/library.js | 14 | ||||
-rwxr-xr-x | tests/runner.py | 13 |
2 files changed, 21 insertions, 6 deletions
diff --git a/src/library.js b/src/library.js index 185b1187..62ef6db2 100644 --- a/src/library.js +++ b/src/library.js @@ -4350,14 +4350,18 @@ LibraryManager.library = { return pdest + i - 1; }, + strncpy__asm: 'true', + strncpy__sig: 'iiii', strncpy: function(pdest, psrc, num) { - var padding = false, curr; - for (var i = 0; i < num; i++) { - curr = padding ? 0 : {{{ makeGetValue('psrc', 'i', 'i8') }}}; + pdest = pdest|0; psrc = psrc|0; num = num|0; + var padding = 0, curr = 0, i = 0; + while ((i|0) < (num|0)) { + curr = padding ? 0 : {{{ makeGetValueAsm('psrc', 'i', 'i8') }}}; {{{ makeSetValue('pdest', 'i', 'curr', 'i8') }}} - padding = padding || {{{ makeGetValue('psrc', 'i', 'i8') }}} == 0; + padding = padding | ({{{ makeGetValueAsm('psrc', 'i', 'i8') }}} == 0); + i = (i+1)|0; } - return pdest; + return pdest|0; }, strlwr__deps:['tolower'], diff --git a/tests/runner.py b/tests/runner.py index 393d8de4..b8fa83f0 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1890,13 +1890,24 @@ Succeeded! printf("%s\\n", strdup_val); free(strdup_val); + { + char *one = "one 1 ONE !"; + char *two = "two 2 TWO ?"; + char three[1024]; + memset(three, '.', 1024); + three[50] = 0; + strncpy(three + argc, one + (argc/2), argc+1); + strncpy(three + argc*3, two + (argc/3), argc+2); + printf("waka %s\\n", three); + } + return 0; } ''' for named in (0, 1): print named Settings.NAMED_GLOBALS = named - self.do_run(src, '4:10,177,543,def\n4\nwowie\ntoo\n76\n5\n(null)\n/* a comment */\n// another\ntest\n', ['wowie', 'too', '74']) + self.do_run(src, '4:10,177,543,def\n4\nwowie\ntoo\n76\n5\n(null)\n/* a comment */\n// another\ntest\nwaka ....e 1 O...wo 2 T................................\n', ['wowie', 'too', '74']) if self.emcc_args == []: gen = open(self.in_dir('src.cpp.o.js')).read() assert ('var __str1;' in gen) == named |