aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-03-18 15:05:12 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-03-18 15:07:17 -0700
commit9642a5128f37371565b53450c8428103b59500f8 (patch)
tree9b5beeb543dde01f91c6e4bb584a9c43a45b89fc /src
parent5685df86fd3a64f5b0e4acfbebab39559b96455d (diff)
check for utf and avoid the overhead if not necessary; remove UTF_STRING_SUPPORT
Diffstat (limited to 'src')
-rw-r--r--src/preamble.js37
-rw-r--r--src/settings.js2
2 files changed, 21 insertions, 18 deletions
diff --git a/src/preamble.js b/src/preamble.js
index 79e225e8..13af4326 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -503,30 +503,35 @@ function allocate(slab, types, allocator, ptr) {
Module['allocate'] = allocate;
function Pointer_stringify(ptr, /* optional */ length) {
-#if UTF_STRING_SUPPORT
- var utf8 = new Runtime.UTF8Processor();
- var nullTerminated = !length;
- var ret = "";
- var i = 0;
+ // Find the length, and check for UTF while doing so
+ var hasUtf = false;
var t;
+ var i = 0;
while (1) {
+ t = {{{ makeGetValue('ptr', 'i', 'i8', 0, 1) }}};
+ if (t >= 128) hasUtf = true;
+ else if (t == 0 && !length) break;
+ i++;
+ if (length && i == length) break;
+ }
+ if (!length) length = i;
+
+#if USE_TYPED_ARRAYS == 2
+ if (!hasUtf) {
+ return String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + length));
+ }
+#endif
+
+ var utf8 = new Runtime.UTF8Processor();
+ var ret = '';
+ for (i = 0; i < length; i++) {
#if ASSERTIONS
- assert(i < TOTAL_MEMORY);
+ assert(ptr + i < TOTAL_MEMORY);
#endif
t = {{{ makeGetValue('ptr', 'i', 'i8', 0, 1) }}};
- if (nullTerminated && t == 0) break;
ret += utf8.processCChar(t);
- i += 1;
- if (!nullTerminated && i == length) break;
}
return ret;
-#else
-#if USE_TYPED_ARRAYS == 2
- return String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + (length || _strlen(ptr))));
-#else
- throw 'unsupported combination';
-#endif
-#endif
}
Module['Pointer_stringify'] = Pointer_stringify;
diff --git a/src/settings.js b/src/settings.js
index c7ed7cd2..97963ac5 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -173,8 +173,6 @@ var GL_UNSAFE_OPTS = 1; // Enables some potentially-unsafe optimizations in GL e
var FULL_ES2 = 0; // Forces support for all GLES2 features, not just the WebGL-friendly subset.
var FORCE_GL_EMULATION = 0; // Forces inclusion of full GL emulation code.
-var UTF_STRING_SUPPORT = 1; // Perform utf-8 conversion between C and JS strings (adds overhead in such conversions)
-
var DISABLE_EXCEPTION_CATCHING = 0; // Disables generating code to actually catch exceptions. If the code you
// are compiling does not actually rely on catching exceptions (but the
// compiler generates code for it, maybe because of stdlibc++ stuff),