Skip to content

Commit c0f8d8c

Browse files
committed
Add S_parse_ident_no_copy()
The way parse_ident() is structured, it uses filling the output buffer to determine if an identifier has too many bytes in it. It would be a pain to restructure it to not do that. So S_parse_ident_no_copy() is created to wrap plain parse_ident(), so that callers that don't care about getting the output buffer don't have to deal with it. These parsing functions are cold code; there is no need to try to eke out every bit of performance from them.
1 parent caaaac0 commit c0f8d8c

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

embed.fnc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6174,6 +6174,11 @@ S |char * |parse_ident |SPTR const char *s \
61746174
|EPTR char * const e \
61756175
|bool is_utf8 \
61766176
|U32 flags
6177+
S |char * |parse_ident_no_copy \
6178+
|SPTR const char *s \
6179+
|EPTR const char * const s_end \
6180+
|bool is_utf8 \
6181+
|U32 flags
61776182
S |int |pending_ident
61786183
RS |char * |scan_const |NN char *start
61796184
RS |char * |scan_formline |NN char *s

embed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,7 @@
16881688
# define lop(a,b,c,d) S_lop(aTHX_ a,b,c,d)
16891689
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
16901690
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)
1691+
# define parse_ident_no_copy(a,b,c,d) S_parse_ident_no_copy(aTHX_ a,b,c,d)
16911692
# define pending_ident() S_pending_ident(aTHX)
16921693
# define scan_const(a) S_scan_const(aTHX_ a)
16931694
# define scan_formline(a) S_scan_formline(aTHX_ a)

proto.h

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

toke.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10471,6 +10471,22 @@ S_parse_ident(pTHX_ const char *s, const char * const s_end,
1047110471
croak("%s", ident_too_long);
1047210472
}
1047310473

10474+
PERL_STATIC_INLINE char *
10475+
S_parse_ident_no_copy(pTHX_ const char *s, const char * const s_end,
10476+
bool is_utf8, U32 flags)
10477+
{
10478+
PERL_ARGS_ASSERT_PARSE_IDENT_NO_COPY;
10479+
10480+
/* This just wraps parse_ident for functions that call it and don't need
10481+
* the actual identifier string returned. For example, they might just
10482+
* want to test if the input is valid. */
10483+
10484+
char scratch[ PERL_IDENTIFIER_LENGTH ];
10485+
char * dest = scratch;
10486+
10487+
return parse_ident(s, s_end, &dest, C_ARRAY_END(scratch), is_utf8, flags);
10488+
}
10489+
1047410490
char *
1047510491
Perl_scan_word(pTHX_ char *s, char *dest, char * dest_end, int allow_package, STRLEN *slp)
1047610492
{

0 commit comments

Comments
 (0)