Skip to content

Commit bd4c0d1

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 9bc8cde commit bd4c0d1

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
@@ -6182,6 +6182,11 @@ S |char * |parse_ident |SPTR const char *s \
61826182
|EPTR char * const e \
61836183
|bool is_utf8 \
61846184
|U32 flags
6185+
S |char * |parse_ident_no_copy \
6186+
|SPTR const char *s \
6187+
|EPTR const char * const s_end \
6188+
|bool is_utf8 \
6189+
|U32 flags
61856190
S |int |pending_ident
61866191
RS |char * |scan_const |NN char *start
61876192
RS |char * |scan_formline |NN char *s

embed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,7 @@
16891689
# define lop(a,b,c,d) S_lop(aTHX_ a,b,c,d)
16901690
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
16911691
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)
1692+
# define parse_ident_no_copy(a,b,c,d) S_parse_ident_no_copy(aTHX_ a,b,c,d)
16921693
# define pending_ident() S_pending_ident(aTHX)
16931694
# define scan_const(a) S_scan_const(aTHX_ a)
16941695
# 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
@@ -10712,6 +10712,22 @@ S_parse_ident(pTHX_ const char *s, const char * const s_end,
1071210712
croak("%s", ident_too_long);
1071310713
}
1071410714

10715+
PERL_STATIC_INLINE char *
10716+
S_parse_ident_no_copy(pTHX_ const char *s, const char * const s_end,
10717+
bool is_utf8, U32 flags)
10718+
{
10719+
PERL_ARGS_ASSERT_PARSE_IDENT_NO_COPY;
10720+
10721+
/* This just wraps parse_ident for functions that call it and don't need
10722+
* the actual identifier string returned. For example, they might just
10723+
* want to test if the input is valid. */
10724+
10725+
char scratch[ PERL_IDENTIFIER_LENGTH ];
10726+
char * dest = scratch;
10727+
10728+
return parse_ident(s, s_end, &dest, C_ARRAY_END(scratch), is_utf8, flags);
10729+
}
10730+
1071510731
char *
1071610732
Perl_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
1071710733
{

0 commit comments

Comments
 (0)