about the implement of the PyString_InternFromString
Heiko Wundram
me+python at modelnine.org
Thu May 4 07:57:23 EDT 2006
Am Donnerstag 04 Mai 2006 13:44 schrieb Kyo Guan:
> Hi guys:
>
> I have a question about the this API.
>
> PyObject *
> PyString_InternFromString(const char *cp)
> {
> PyObject *s = PyString_FromString(cp);
> if (s == NULL)
> return NULL;
> PyString_InternInPlace(&s);
> return s;
> }
>
>
> Why it always try to call PyString_FromString first? if char* cp is
> already in the interned dict, this PyString_FromString call is waster. so I
> think this API should implement as:
Have you looked at the type of cp? It's const char*, that's not a Python type.
PyString_FromString does nothing else than create a Python string-object from
the C string, which can then in turn be interned. This call is necessary.
--- Heiko.
More information about the Python-list
mailing list