[number] Minor tweak on parser related codes
diff --git a/src/hb-algs.hh b/src/hb-algs.hh
index 96cc157..66433a2 100644
--- a/src/hb-algs.hh
+++ b/src/hb-algs.hh
@@ -900,10 +900,10 @@
unsigned int v;
const char *p = s;
const char *end = p + len;
- if (!hb_parse_uint (&p, p + len, &v, base))
- return false;
+ if (unlikely (!hb_parse_uint (&p, end, &v, base))) return false;
- if (end != p && *p) return false;
+ /* Pain because we don't know whether s is nul-terminated. */
+ if (unlikely (p != end && *p)) return false;
*out = v;
return true;
diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc
index a6e3bb8..5f65d31 100644
--- a/src/hb-buffer-serialize.cc
+++ b/src/hb-buffer-serialize.cc
@@ -384,12 +384,10 @@
{
int v;
const char *p = pp;
- if (!hb_parse_int (&p, end, &v))
- return false;
+ if (unlikely (!hb_parse_int (&p, end, &v))) return false;
/* Check if parser consumed all of the buffer */
- if (p != end)
- return false;
+ if (unlikely (p != end)) return false;
*pv = v;
return true;
diff --git a/src/hb-common.cc b/src/hb-common.cc
index 690c96f..6ad8346 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -721,11 +721,10 @@
static bool
parse_uint (const char **pp, const char *end, unsigned int *pv)
{
- /* Intentionally use strtol inside instead of strtoul, such that
- * -1 turns into "big number"... */
+ /* Intentionally use hb_parse_int inside instead of hb_parse_uint,
+ * such that -1 turns into "big number"... */
int v;
- if (!hb_parse_int (pp, end, &v))
- return false;
+ if (unlikely (!hb_parse_int (pp, end, &v))) return false;
*pv = v;
return true;
@@ -734,11 +733,10 @@
static bool
parse_uint32 (const char **pp, const char *end, uint32_t *pv)
{
- /* Intentionally use strtol inside instead of strtoul, such that
- * -1 turns into "big number"... */
+ /* Intentionally use hb_parse_int inside instead of hb_parse_uint,
+ * such that -1 turns into "big number"... */
int v;
- if (!hb_parse_int (pp, end, &v))
- return false;
+ if (unlikely (!hb_parse_int (pp, end, &v))) return false;
*pv = v;
return true;
diff --git a/src/hb-number.cc b/src/hb-number.cc
index 4a86ddd..d5acd2b 100644
--- a/src/hb-number.cc
+++ b/src/hb-number.cc
@@ -32,7 +32,7 @@
#endif
template<typename T, typename Func>
-static inline bool
+static bool
_parse_number (const char **pp, const char *end, T *pv, Func f)
{
char buf[32];
@@ -42,13 +42,11 @@
char *p = buf;
char *pend = p;
- T v;
errno = 0;
- v = f (p, &pend);
+ *pv = f (p, &pend);
if (unlikely (errno || p == pend)) return false;
- *pv = v;
*pp += pend - p;
return true;
}