This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH RFA: Make hashtable::clear return quickly if table is empty


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...


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]