From 36e57486f01fc026fd1e8886b32f91e385befedc Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 3 Feb 2016 14:52:43 +0000 Subject: Bug 696546: Add fast strtof Take on a (slightly tweaked) version of Simon Reinhardt's patch. The actual logic is left entirely unchanged; minor changes have been made to the names of functions/types to avoid clashing in the cmapdump.c repeated inclusion. Currently this should really only affect xps files, as strtof is only used as fz_atof, and that's (effectively) all xps for now. I will look at updating lex_number to call this in future. --- source/fitz/string.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'source/fitz/string.c') diff --git a/source/fitz/string.c b/source/fitz/string.c index b625dd4d..d22efe8e 100644 --- a/source/fitz/string.c +++ b/source/fitz/string.c @@ -354,20 +354,15 @@ fz_runelen(int c) float fz_atof(const char *s) { - double d; + float result; - /* The errno voodoo here checks for us reading numbers that are too - * big to fit into a double. The checks for FLT_MAX ensure that we - * don't read a number that's OK as a double and then become invalid - * as we convert to a float. */ errno = 0; - d = fz_strtod(s, NULL); - if (errno == ERANGE || isnan(d)) { - /* Return 1.0, as it's a small known value that won't cause a divide by 0. */ - return 1.0; - } - d = fz_clampd(d, -FLT_MAX, FLT_MAX); - return (float)d; + result = fz_strtof(s, NULL); + if ((errno == ERANGE && result == 0) || isnan(result)) + /* Return 1.0 on underflow, as it's a small known value that won't cause a divide by 0. */ + return 1; + result = fz_clamp(result, -FLT_MAX, FLT_MAX); + return result; } int fz_atoi(const char *s) -- cgit v1.2.3