Skip to content

Commit

Permalink
Use much faster atoi function. 14% less CPU use when slurping a Unico…
Browse files Browse the repository at this point in the history
…de file

This should greatly speed up any calls made to ccc which is used
extensively in MVM_unicode_normalizer_process_codepoint_full and
canonical_composition.
  • Loading branch information
samcv committed Jan 4, 2017
1 parent a4fbf52 commit d0e297f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/strings/normalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,21 @@ static MVMint64 passes_quickcheck(MVMThreadContext *tc, const MVMNormalizer *n,
return pval && pval[0] == 'Y';
}

MVM_STATIC_INLINE MVMint32 fast_atoi( const char * dec_str ) {
MVMint32 value = 0;
while( *dec_str ) {
value = value*10 + (*dec_str++ - '0');
}
return value;
}
/* Gets the canonical combining class for a codepoint. */
static MVMint64 ccc(MVMThreadContext *tc, MVMCodepoint cp) {
if (cp < MVM_NORMALIZE_FIRST_NONZERO_CCC) {
return 0;
}
else {
const char *ccc_str = MVM_unicode_codepoint_get_property_cstr(tc, cp, MVM_UNICODE_PROPERTY_CANONICAL_COMBINING_CLASS);
return !ccc_str || strlen(ccc_str) > 3 ? 0 : atoi(ccc_str);
return !ccc_str || strlen(ccc_str) > 3 ? 0 : fast_atoi(ccc_str);
}
}

Expand Down

0 comments on commit d0e297f

Please sign in to comment.