This is an automated email from the ASF dual-hosted git repository.

nickva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-jiffy.git

commit e2411f566346aa4f07be4efd76391e5952866760
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Fri Jun 12 20:11:14 2026 -0400

    Update ffc.h : faster numbers parsing
    
    A quick microbench showed 10% speedup on numbers.json.
    
    Upstream PR: https://github.com/kolemannix/ffc.h/pull/23
---
 c_src/ffc.h | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/c_src/ffc.h b/c_src/ffc.h
index 056b6f9..3a1e20a 100644
--- a/c_src/ffc.h
+++ b/c_src/ffc.h
@@ -114,8 +114,8 @@ extern "C" {
 #define FFC_API
 
 #define FFC_VERSION_YEAR  26
-#define FFC_VERSION_MONTH 03
-#define FFC_VERSION_BUILD 03
+#define FFC_VERSION_MONTH 04
+#define FFC_VERSION_BUILD 01
 #define FFC_VERSION ((FFC_VERSION_YEAR << 16) | (FFC_VERSION_MONTH << 8) | 
(FFC_VERSION_BUILD))
 #define FFC_VERSION_STRINGIFY_(x) #x
 #define FFC_VERSION_STRINGIFY(x) FFC_VERSION_STRINGIFY_(x)
@@ -1125,13 +1125,22 @@ ffc_internal ffc_inline void
 ffc_loop_parse_if_eight_digits(char const **p, char const *const pend,
                            uint64_t* i) {
   // optimizes better than parse_if_eight_digits_unrolled() for char.
-  while ((pend - *p >= 8) &&
-         ffc_is_made_of_eight_digits_fast(ffc_read8_to_u64(*p))) {
-    *i = (*i * 100000000) +
-        ffc_parse_eight_digits_unrolled_swar(ffc_read8_to_u64(*p)); 
+  while (pend - *p >= 8) {
+    uint64_t val = ffc_read8_to_u64(*p);
+    if (!ffc_is_made_of_eight_digits_fast(val)) { break; }
+    *i = (*i * 100000000) + ffc_parse_eight_digits_unrolled_swar(val);
         // in rare cases, this will overflow, but that's ok
     *p += 8;
   }
+  // 4-digit follow-up: handles sub-8 remainders (e.g. 7-digit fractions)
+  // without falling all the way to byte-by-byte for the first 4 digits.
+  if (pend - *p >= 4) {
+    uint32_t val4 = ffc_read4_to_u32(*p);
+    if (ffc_is_made_of_four_digits_fast(val4)) {
+      *i = (*i * 10000) + ffc_parse_four_digits_unrolled(val4);
+      *p += 4;
+    }
+  }
 }
 
 /* section end: read digits */

Reply via email to