This is an archive of the discontinued LLVM Phabricator instance.

Adjust initial size in StringMap constructor to guarantee no grow()
ClosedPublic

Authored by mehdi_amini on Mar 21 2016, 11:15 PM.

Details

Summary

StringMap ctor accepts an initialize size, but expect it to be
rounded to the next power of 2. The ctor can handle that directly
instead of expecting clients to round it. Also, since the map will
resize itself when 75% full, take this into account an initialize
a larger initial size to avoid any growth.

Diff Detail

Event Timeline

mehdi_amini retitled this revision from to Adjust initial size in StringMap constructor to guarantee no grow().
mehdi_amini updated this object.
mehdi_amini added a reviewer: dblaikie.
mehdi_amini added a subscriber: llvm-commits.
dblaikie edited edge metadata.Mar 22 2016, 8:31 AM
dblaikie added a subscriber: dblaikie.

Could you include a test that demonstrates non-growth (I think someone
contributed a similar patch for DenseMap's growth recently - could check
how that was tested (I think it could be tested better with a move-counting
object, for example, but not a strict requirement))?

mehdi_amini edited edge metadata.

Add test and refactor

dblaikie accepted this revision.Mar 22 2016, 5:39 PM
dblaikie edited edge metadata.

Seems good to me otherwise.

unittests/ADT/StringMapTest.cpp
385–386

feels a bit off to say "picked without any good reason" - we should have reasons for things. That doesn't mean the specific values are important, maybe "Sampled test cases - a boundary case, a power of two, and a non-power-of-two" ? Not sure

This revision is now accepted and ready to land.Mar 22 2016, 5:39 PM