On 18 August 2014 19:50, <stefan2_at_apache.org> wrote:
> Author: stefan2
> Date: Mon Aug 18 15:50:44 2014
> New Revision: 1618641
>
> URL: http://svn.apache.org/r1618641
> Log:
> Within FSFS, replace the use of svn__strtol with a variant that
> provides overflow detection. FSFS needs a locale-independent
> and preferrably quick number parser.
>
[...]
> ==============================================================================
> --- subversion/trunk/subversion/libsvn_fs_fs/id.c (original)
> +++ subversion/trunk/subversion/libsvn_fs_fs/id.c Mon Aug 18 15:50:44 2014
> @@ -48,12 +48,55 @@ typedef struct fs_fs__id_t
>
>
>
> +/** Like strtol but with a fixed base of 10, locale independent and limited
> + * to non-negative values. Overflows are indicated by a FALSE return value
> + * in which case *RESULT_P will not be modified.
> + *
> + * This allows the compiler to generate massively faster code.
> + * (E.g. Avoiding locale specific processing). ID parsing is one of the
> + * most CPU consuming parts of FSFS data access. Better be quick.
> + */
> +static svn_boolean_t
> +fast__strtol(long *result_p,
> + const char* buffer,
> + const char** end)
> +{
> + /* We allow positive values only. Unsigned arithmetics tend to be faster
> + * as they allow for a wider range of compiler-side optimizations. */
> + unsigned long result = 0;
> + while (1)
> + {
> + unsigned long c = (unsigned char)*buffer - (unsigned char)'0';
> + unsigned long next;
> +
> + /* This implies the NUL check. */
> + if (c > 9)
> + break;
> +
> + next = result * 10 + c;
> +
> + /* Overflow check. */
> + if (next < result)
> + return FALSE;
> +
> + result = next;
> + ++buffer;
> + }
> +
> + *end = buffer;
> + *result_p = (long)result;
> +
> + return TRUE;
> +}
> +
Stefan,
It maybe worth to make tests for this function (making it private to
libsvn_subr for this). What do you think?
--
Ivan Zhakov
CTO | VisualSVN | http://www.visualsvn.com
Received on 2014-08-26 18:47:45 CEST