about the implement of the PyString_InternFromString

K

kyo guan

Hi :

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:

1. check the interned dict
2. if cp is not in the dict, then call PyString_FromString, and insert the new string in the dict 3. else : call Py_INCREF and
return.

Is this right?

Kyo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,207
Latest member
KazukoCape

Latest Threads

Top