shithub: libmujs

Download patch

ref: 339abac8ab1ca47db97bc5c7da08065418503e92
parent: 9f181651fb03b9d951ae60ae7ef51589efe69015
author: Tor Andersson <tor.andersson@artifex.com>
date: Fri Nov 7 11:07:56 EST 2014

Optimize js_stringtofloat to use integer conversion when possible.

Use strtol conversion when the number is 9 digits or less,
has no decimal point and no exponent.

--- a/jsvalue.c
+++ b/jsvalue.c
@@ -127,16 +127,21 @@
 	char *end;
 	double n;
 	const char *e = s;
+	int isflt = 0;
 	if (*e == '+' || *e == '-') ++e;
 	while (*e >= '0' && *e <= '9') ++e;
-	if (*e == '.') ++e;
+	if (*e == '.') { ++e; isflt = 1; }
 	while (*e >= '0' && *e <= '9') ++e;
 	if (*e == 'e' || *e == 'E') {
 		++e;
 		if (*e == '+' || *e == '-') ++e;
 		while (*e >= '0' && *e <= '9') ++e;
+		isflt = 1;
 	}
-	n = js_strtod(s, &end);
+	if (isflt || e - s > 9)
+		n = js_strtod(s, &end);
+	else
+		n = strtol(s, &end, 10);
 	if (end == e) {
 		*ep = (char*)e;
 		return n;