This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: PATCH RFA: Make hashtable::clear return quickly if table is empty
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Date: Mon, 30 Mar 2009 11:28:24 +0200
- Subject: Re: PATCH RFA: Make hashtable::clear return quickly if table is empty
- References: <m3ab76ryv0.fsf@google.com>
Hi,
> This is a patch for the old hashtable class used for the old hash_map
> and hash_set classes. These classes are superseded by the newer tr1
> unordered_map and unordered_set classes, but they are still widely used.
>
> Classes and functions can use hash tables which are only used in some
> code paths. When those code paths are not followed, the empty hash
> table will be destroyed when the class is destroyed or the function
> returns. Destroying a hash table calls clear, which walks through all
> the buckets. This is a waste of time if the hash table is empty.
> Testing whether it is empty is a fast test, permitting a fast return
> when empty. The test will take very little time when the hash table is
> not empty, particularly since the _M_num_elements field is right next to
> the _M_buckets field and quite possibly on the same cache line.
>
> Is this patch OK to commit to mainline?
>
Sure it is. Thanks for the exhaustive explanation.
Paolo.
PS: Careful, two more of those and you will be officially appointed
maintainer of the unmaintained library code ;)
PPS: A tad more seriously: we badly lack testcases in some areas, thus,
in the future, please consider exercising a bit the code paths you will
be touching...