Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Factor out store_interned().
  • Loading branch information
ericsnowcurrently committed Mar 22, 2023
commit 7d95514984a496c89a737d501c178e46b954b23e
36 changes: 22 additions & 14 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -14585,6 +14585,24 @@ _PyUnicode_InitTypes(PyInterpreterState *interp)
}


static inline PyObject *
store_interned(PyObject *obj)
{
PyObject *interned = get_interned_dict();
assert(interned != NULL);

// XXX Swap to the main interpreter.

PyObject *t = PyDict_SetDefault(interned, obj, obj);
if (t == NULL) {
PyErr_Clear();
}

// XXX Swap back.

return t;
}

void
PyUnicode_InternInPlace(PyObject **p)
{
Expand All @@ -14608,21 +14626,11 @@ PyUnicode_InternInPlace(PyObject **p)
return;
}

PyObject *interned = get_interned_dict();
assert(interned != NULL);

// XXX Swap to the main interpreter.

PyObject *t = PyDict_SetDefault(interned, s, s);
if (t == NULL) {
PyErr_Clear();
return;
}

// XXX Swap back.

PyObject *t = store_interned(s);
if (t != s) {
Py_SETREF(*p, Py_NewRef(t));
if (t != NULL) {
Py_SETREF(*p, Py_NewRef(t));
}
return;
}

Expand Down