A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-March/052269.html below:

[Python-Dev] Faster Set.discard() method?

[Python-Dev] Faster Set.discard() method? [Python-Dev] Faster Set.discard() method?Andrew McNamara andrewm at object-craft.com.au
Fri Mar 18 07:19:44 CET 2005
>The C implementation has this code:
>
>"""
>	if (PyDict_DelItem(so->data, item) == -1) {
>		if (!PyErr_ExceptionMatches(PyExc_KeyError))
>			return NULL;
>		PyErr_Clear();
>	}
>"""
>
>Which is more-or-less the same as the sets.Set version, right?  What I was
>wondering was whether changing that C to a C version of your dict.pop()
>version would also result in speedups.  Are Exceptions really that slow,
>even at the C level?

No, exceptions are fast at the C level - all they do is set a flag. The
expense of exceptions is saving a restoring python frames, I think,
which doesn't happen in this case. So the current implementation is
ideal for C code - clear and fast.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4