about the implement of the PyString_InternFromString

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kyo Guan

    #1

    about the implement of the PyString_InternFromString


    Hi guys:

    I have a question about the this API.

    PyObject *
    PyString_Intern FromString(cons t char *cp)
    {
    PyObject *s = PyString_FromSt ring(cp);
    if (s == NULL)
    return NULL;
    PyString_Intern InPlace(&s);
    return s;
    }


    Why it always try to call PyString_FromSt ring first? if char* cp is already in the
    interned dict, this PyString_FromSt ring 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_FromSt ring, and insert the new string in
    the dict
    3. else : call Py_INCREF and return.

    Is this right?

    Kyo.


Working...