aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2014-03-16 04:11:23 +0200
committerJukka Jylänki <jujjyl@gmail.com>2014-03-28 23:06:17 -0400
commit64300b2ea56bfe6f09f855cfd7f7f6d99ec39bfe (patch)
tree321fbe00d7b073c0ef829d279786809ce0955056
parentbbc711d5c719bbd14cd7849309e89608ae13d287 (diff)
Migrate to using musl 0.9.13 strtok and strtok_r for better asm.js performance.
-rw-r--r--src/library.js59
-rw-r--r--system/lib/libc/musl/src/string/strtok.c13
-rw-r--r--system/lib/libc/musl/src/string/strtok_r.c12
-rw-r--r--system/lib/libcextra.symbols2
-rw-r--r--tools/system_libs.py2
5 files changed, 29 insertions, 59 deletions
diff --git a/src/library.js b/src/library.js
index e7298721..935d07e6 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3639,65 +3639,6 @@ LibraryManager.library = {
return pdest|0;
},
- __strtok_state: 0,
- strtok__deps: ['__strtok_state', 'strtok_r'],
- strtok__postset: '___strtok_state = Runtime.staticAlloc(4);',
- strtok: function(s, delim) {
- return _strtok_r(s, delim, ___strtok_state);
- },
-
- // Translated from newlib; for the original source and licensing, see library_strtok_r.c
- strtok_r: function(s, delim, lasts) {
- var skip_leading_delim = 1;
- var spanp;
- var c, sc;
- var tok;
-
-
- if (s == 0 && (s = getValue(lasts, 'i8*')) == 0) {
- return 0;
- }
-
- cont: while (1) {
- c = getValue(s++, 'i8');
- for (spanp = delim; (sc = getValue(spanp++, 'i8')) != 0;) {
- if (c == sc) {
- if (skip_leading_delim) {
- continue cont;
- } else {
- setValue(lasts, s, 'i8*');
- setValue(s - 1, 0, 'i8');
- return s - 1;
- }
- }
- }
- break;
- }
-
- if (c == 0) {
- setValue(lasts, 0, 'i8*');
- return 0;
- }
- tok = s - 1;
-
- for (;;) {
- c = getValue(s++, 'i8');
- spanp = delim;
- do {
- if ((sc = getValue(spanp++, 'i8')) == c) {
- if (c == 0) {
- s = 0;
- } else {
- setValue(s - 1, 0, 'i8');
- }
- setValue(lasts, s, 'i8*');
- return tok;
- }
- } while (sc != 0);
- }
- abort('strtok_r error!');
- },
-
strerror_r__deps: ['$ERRNO_CODES', '$ERRNO_MESSAGES', '__setErrNo'],
strerror_r: function(errnum, strerrbuf, buflen) {
if (errnum in ERRNO_MESSAGES) {
diff --git a/system/lib/libc/musl/src/string/strtok.c b/system/lib/libc/musl/src/string/strtok.c
new file mode 100644
index 00000000..35087902
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strtok.c
@@ -0,0 +1,13 @@
+#include <string.h>
+
+char *strtok(char *restrict s, const char *restrict sep)
+{
+ static char *p;
+ if (!s && !(s = p)) return NULL;
+ s += strspn(s, sep);
+ if (!*s) return p = 0;
+ p = s + strcspn(s, sep);
+ if (*p) *p++ = 0;
+ else p = 0;
+ return s;
+}
diff --git a/system/lib/libc/musl/src/string/strtok_r.c b/system/lib/libc/musl/src/string/strtok_r.c
new file mode 100644
index 00000000..862d4fe4
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strtok_r.c
@@ -0,0 +1,12 @@
+#include <string.h>
+
+char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p)
+{
+ if (!s && !(s = *p)) return NULL;
+ s += strspn(s, sep);
+ if (!*s) return *p = 0;
+ *p = s + strcspn(s, sep);
+ if (**p) *(*p)++ = 0;
+ else *p = 0;
+ return s;
+}
diff --git a/system/lib/libcextra.symbols b/system/lib/libcextra.symbols
index 7846f153..64ba670a 100644
--- a/system/lib/libcextra.symbols
+++ b/system/lib/libcextra.symbols
@@ -131,6 +131,8 @@
T strsep
T strspn
T strstr
+ T strtok
+ T strtok_r
T strverscmp
T strxfrm
W strxfrm_l
diff --git a/tools/system_libs.py b/tools/system_libs.py
index b6acd0a1..50910a8a 100644
--- a/tools/system_libs.py
+++ b/tools/system_libs.py
@@ -259,6 +259,8 @@ def calculate(temp_files, in_temp, stdout, stderr):
'strsep.c',
'strspn.c',
'strstr.c',
+ 'strtok.c',
+ 'strtok_r.c',
'strverscmp.c',
'wcpcpy.c',
'wcpncpy.c',