summaryrefslogtreecommitdiff
path: root/proto.h
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-01-10 11:45:39 -0700
committerKarl Williamson <khw@cpan.org>2020-01-13 20:58:56 -0700
commitc969ff22d59d2aa1fa495b790f009037dc500787 (patch)
tree9dff45a770839d057665f4ef17facd4000bdf0a1 /proto.h
parent4b24f70353412ec749279fbcdb75b84ffd574c1c (diff)
downloadperl-c969ff22d59d2aa1fa495b790f009037dc500787.tar.gz
Improve performance of grok_bin_oct_hex()
This commit uses a variety of techniques for speeding this up. It is now faster than blead, and has less maintenance cost than before. Most of the checks that the current character isn't NUL are unnecssary. The logic works on that character, even if, for some reason, you can't trust the input length. A special test is added to not output the illegal character message if that character is a NUL. This is simply for backcompat. And a switch statement is used to unroll the loop for the leading digits in the number. This should handle most common cases. Beyond these, and one has to start worrying about overflow. So this version has removed that worrying from the common cases. Extra conditionals are avoided for large numbers by extracting the portability warning message code into a separate static function called from two different places. Simplifying this logic led me to see that if it overflowed, it must be non-portable, so another conditional could be removed. Other conditionals were removed at the expense of adding parameters to the function. This function isn't public, but is called from the grok_hex, et. al. macros. grok_hex knows, for example, that it is looking for an 'x' prefix and not a 'b'. Previously the code had a conditional to determine that. Similarly in pp.c, we look for the prefix. Having found it we can start the parse after the prefix, and tell this function not to look for it. Previously, this work was duplicated. The previous changes had left this function slower than blead. That is in part due to the fact that the loop doesn't go through that many iterations per function call, and the gcc compiler managed to optimize away the conditionals in XDIGIT_VALUE in the call of it from the loop. (The other call in this function did have the conditionals.) Thanks to Sergey Aleynikov for his help on this
Diffstat (limited to 'proto.h')
-rw-r--r--proto.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/proto.h b/proto.h
index 7c719b5e42..deed243a19 100644
--- a/proto.h
+++ b/proto.h
@@ -1148,7 +1148,7 @@ PERL_CALLCONV bool Perl_grok_atoUV(const char* pv, UV* valptr, const char** endp
PERL_CALLCONV UV Perl_grok_bin(pTHX_ const char* start, STRLEN* len_p, I32* flags, NV *result);
#define PERL_ARGS_ASSERT_GROK_BIN \
assert(start); assert(len_p); assert(flags)
-PERL_CALLCONV UV Perl_grok_bin_oct_hex(pTHX_ const char* start, STRLEN* len_p, I32* flags, NV *result, const unsigned shift);
+PERL_CALLCONV UV Perl_grok_bin_oct_hex(pTHX_ const char* start, STRLEN* len_p, I32* flags, NV *result, const unsigned shift, const U8 lookup_bit, const char prefix);
#define PERL_ARGS_ASSERT_GROK_BIN_OCT_HEX \
assert(start); assert(len_p); assert(flags)
PERL_CALLCONV UV Perl_grok_hex(pTHX_ const char* start, STRLEN* len_p, I32* flags, NV *result);
@@ -5098,6 +5098,10 @@ STATIC AV* S_mro_get_linear_isa_dfs(pTHX_ HV* stash, U32 level);
#define PERL_ARGS_ASSERT_MRO_GET_LINEAR_ISA_DFS \
assert(stash)
#endif
+#if defined(PERL_IN_NUMERIC_C)
+STATIC void S_output_non_portable(pTHX_ const U8 shift);
+#define PERL_ARGS_ASSERT_OUTPUT_NON_PORTABLE
+#endif
#if defined(PERL_IN_OP_C)
STATIC void S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs);
#define PERL_ARGS_ASSERT_APPLY_ATTRS \