Skip to content

Commit 36797cb

Browse files
committed
Add S_parse_ident_no_copy()
This new function is for callers that are merely checking if the string being parsed is a legal identifier or not, and arent interested in the normalized version of the identifier that parse_indent() generates. This new function allows callers to not have to think about this buffer; it just wraps plain parse_ident() using a throw-away buffer to hold the returned normalized text. This avoids introducing a bunch of conditionals inside parse_ident.
1 parent bd66bfa commit 36797cb

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
@@ -10464,6 +10464,22 @@ S_parse_ident(pTHX_ const char *s, const char * const s_end,
1046410464
croak("%s", ident_too_long);
1046510465
}
1046610466

10467+
PERL_STATIC_INLINE char *
10468+
S_parse_ident_no_copy(pTHX_ const char *s, const char * const s_end,
10469+
bool is_utf8, U32 flags)
10470+
{
10471+
PERL_ARGS_ASSERT_PARSE_IDENT_NO_COPY;
10472+
10473+
/* This just wraps parse_ident for functions that call it and don't need
10474+
* the actual identifier string returned. For example, they might just
10475+
* want to test if the input is valid. */
10476+
10477+
char scratch[ PERL_IDENTIFIER_LENGTH ];
10478+
char * dest = scratch;
10479+
10480+
return parse_ident(s, s_end, &dest, C_ARRAY_END(scratch), is_utf8, flags);
10481+
}
10482+
1046710483
char *
1046810484
Perl_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
1046910485
{

0 commit comments

Comments
 (0)