summaryrefslogtreecommitdiff
path: root/source/fitz/string.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-02-03 14:52:43 +0000
committerRobin Watts <robin.watts@artifex.com>2016-02-03 16:34:24 +0000
commit36e57486f01fc026fd1e8886b32f91e385befedc (patch)
tree43c2cf9f99e70539aea65c7b889427fd84a4270e /source/fitz/string.c
parentd9c24f4fea589ab65a6046769c0642206557e60d (diff)
downloadmupdf-36e57486f01fc026fd1e8886b32f91e385befedc.tar.xz
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.
Diffstat (limited to 'source/fitz/string.c')
-rw-r--r--source/fitz/string.c19
1 files changed, 7 insertions, 12 deletions
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)