/ Check-in [81721aa5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Performance enhancement in sqlite3AtoF(). About 8% faster.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 81721aa54587e20d031d528fb6b74d91671a6e950fa926dc63f4284466e70f0e
User & Date: drh 2019-05-25 18:17:53
Context
2019-05-27
00:29
Improved rounding even on systems with an 8-byte "long double" type. check-in: 15202aee user: drh tags: trunk
2019-05-25
18:17
Performance enhancement in sqlite3AtoF(). About 8% faster. check-in: 81721aa5 user: drh tags: trunk
17:41
Use "long double" literals to initialize an array of "long double" objects. check-in: 2e2ebad3 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/util.c.

   419    419     int sign = 1;    /* sign of significand */
   420    420     i64 s = 0;       /* significand */
   421    421     int d = 0;       /* adjust exponent for shifting decimal point */
   422    422     int esign = 1;   /* sign of exponent */
   423    423     int e = 0;       /* exponent */
   424    424     int eValid = 1;  /* True exponent is either not used or is well-formed */
   425    425     double result;
   426         -  int nDigits = 0;
          426  +  int nDigit = 0;  /* Number of digits processed */
   427    427     int nonNum = 0;  /* True if input contains UTF16 with high byte non-zero */
   428    428   
   429    429     assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
   430    430     *pResult = 0.0;   /* Default return value, in case of an error */
   431    431   
   432    432     if( enc==SQLITE_UTF8 ){
   433    433       incr = 1;
................................................................................
   450    450       sign = -1;
   451    451       z+=incr;
   452    452     }else if( *z=='+' ){
   453    453       z+=incr;
   454    454     }
   455    455   
   456    456     /* copy max significant digits to significand */
   457         -  while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
          457  +  while( z<zEnd && sqlite3Isdigit(*z) ){
   458    458       s = s*10 + (*z - '0');
   459         -    z+=incr; nDigits++;
          459  +    z+=incr; nDigit++;
          460  +    if( s>=((LARGEST_INT64-9)/10) ){
          461  +      /* skip non-significant significand digits
          462  +      ** (increase exponent by d to shift decimal left) */
          463  +      while( z<zEnd && sqlite3Isdigit(*z) ){ z+=incr; d++; }
          464  +    }
   460    465     }
   461         -
   462         -  /* skip non-significant significand digits
   463         -  ** (increase exponent by d to shift decimal left) */
   464         -  while( z<zEnd && sqlite3Isdigit(*z) ){ z+=incr; nDigits++; d++; }
   465    466     if( z>=zEnd ) goto do_atof_calc;
   466    467   
   467    468     /* if decimal point is present */
   468    469     if( *z=='.' ){
   469    470       z+=incr;
   470    471       /* copy digits from after decimal to significand
   471    472       ** (decrease exponent by d to shift decimal right) */
   472    473       while( z<zEnd && sqlite3Isdigit(*z) ){
   473    474         if( s<((LARGEST_INT64-9)/10) ){
   474    475           s = s*10 + (*z - '0');
   475    476           d--;
          477  +        nDigit++;
   476    478         }
   477         -      z+=incr; nDigits++;
          479  +      z+=incr;
   478    480       }
   479    481     }
   480    482     if( z>=zEnd ) goto do_atof_calc;
   481    483   
   482    484     /* if exponent is present */
   483    485     if( *z=='e' || *z=='E' ){
   484    486       z+=incr;
................................................................................
   577    579       }
   578    580     }
   579    581   
   580    582     /* store the result */
   581    583     *pResult = result;
   582    584   
   583    585     /* return true if number and no extra non-whitespace chracters after */
   584         -  return z==zEnd && nDigits>0 && eValid && nonNum==0;
          586  +  return z==zEnd && nDigit>0 && eValid && nonNum==0;
   585    587   #else
   586    588     return !sqlite3Atoi64(z, pResult, length, enc);
   587    589   #endif /* SQLITE_OMIT_FLOATING_POINT */
   588    590   }
   589    591   
   590    592   /*
   591    593   ** Compare the 19-character string zNum against the text representation