summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-01-19 00:24:06 (GMT)
committerGuido van Rossum <guido@python.org>2001-01-19 00:24:06 (GMT)
commitfc5ce61abd7f21c2674afc49cc1f2659bef2aa20 (patch)
tree1f03046066dd5a336a9df6330bd263052f15eac0 /Python/compile.c
parent2312024eb734a82bd9f190d21a18f693c5815725 (diff)
downloadcpython-fc5ce61abd7f21c2674afc49cc1f2659bef2aa20.zip
cpython-fc5ce61abd7f21c2674afc49cc1f2659bef2aa20.tar.gz
cpython-fc5ce61abd7f21c2674afc49cc1f2659bef2aa20.tar.bz2
SF Patch #103250, by pj99: Optimize a strspn() out of startup.
Minor startup speedup: avoid a call to strspn().
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c
index aca1705..734bfcf5 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -164,6 +164,26 @@ PyTypeObject PyCode_Type = {
#define NAME_CHARS \
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
+/* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
+
+static int
+all_name_chars(unsigned char *s)
+{
+ static char ok_name_char[256];
+ static unsigned char *name_chars = NAME_CHARS;
+
+ if (ok_name_char[*name_chars] == 0) {
+ unsigned char *p;
+ for (p = name_chars; *p; p++)
+ ok_name_char[*p] = 1;
+ }
+ while (*s) {
+ if (ok_name_char[*s++] == 0)
+ return 0;
+ }
+ return 1;
+}
+
PyCodeObject *
PyCode_New(int argcount, int nlocals, int stacksize, int flags,
PyObject *code, PyObject *consts, PyObject *names,
@@ -214,12 +234,9 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags,
/* Intern selected string constants */
for (i = PyTuple_Size(consts); --i >= 0; ) {
PyObject *v = PyTuple_GetItem(consts, i);
- char *p;
if (!PyString_Check(v))
continue;
- p = PyString_AsString(v);
- if (strspn(p, NAME_CHARS)
- != (size_t)PyString_Size(v))
+ if (!all_name_chars((unsigned char *)PyString_AsString(v)))
continue;
PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i));
}