cxx/include
Howard Hinnant 4b2f4203a2 Performance tweaking rotate.
rotate is a critical algorithm because it is often used by other algorithms,
both std and non-std.  The main thrust of this optimization is a specialized
algorithm when the 'distance' to be shifted is 1 (either left or right).  To my
surprise, this 'optimization' was not effective for types like std::string.
std::string favors rotate algorithms which only use swap.  But for types like
scalars, and especially when the sequence is random access, these new
specializations are a big win.  If it is a vector<size_t> for example, the
rotate is done via a memmove and can be several times faster than the gcd
algorithm.

I'm using is_trivially_move_assignable to distinguish between types like int and
types like string.  This is obviously an ad-hoc approximation, but I haven't
found a case where it doesn't give good results.

I've used a 'static if' (with is_trivially_move_assignable) in three places. 
Testing with both -Os and -O3 showed that clang eliminated all code not be
executed by the 'static if' (including the 'static if' itself).

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@161247 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-03 18:01:20 +00:00
..
2012-07-07 17:04:52 +00:00
This commit establishes a new bucket_count policy in the unordered containers: The policy now allows a power-of-2 number of buckets to be requested (and that request honored) by the client. And if the number of buckets is set to a power of 2, then the constraint of the hash to the number of buckets uses & instead of %. If the client does not specify a number of buckets, then the policy remains unchanged: a prime number of buckets is selected. The growth policy is that the number of buckets is roughly doubled when needed. While growing, either the prime, or the power-of-2 strategy will be preserved. There is a small run time cost for putting in this switch. For very cheap hash functions, e.g. identity for int, the cost can be as high as 18%. However with more typical use cases, e.g. strings, the cost is in the noise level. I've measured cases with very cheap hash functions (int) that using a power-of-2 number of buckets can make look up about twice as fast. However I've also noted that a power-of-2 number of buckets is more susceptible to accidental catastrophic collisions. Though I've also noted that accidental catastrophic collisions are also possible when using a prime number of buckets (but seems far less likely). In short, this patch adds an extra tuning knob for those clients trying to get the last bit of performance squeezed out of their hash containers. Casual users of the hash containers will not notice the introduction of this tuning knob. Those clients who swear by power-of-2 hash containers can now opt-in to that strategy. Clients who prefer a prime number of buckets can continue as they have.
2012-07-06 17:31:14 +00:00
2011-12-01 20:21:04 +00:00
2011-10-17 20:05:10 +00:00
2012-08-03 18:01:20 +00:00
2012-07-20 19:20:49 +00:00
2012-07-07 17:04:52 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-13 19:17:27 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-20 22:18:27 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
ios
2012-07-21 01:03:40 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-20 19:36:34 +00:00
2011-10-17 20:05:10 +00:00
2012-07-20 21:44:27 +00:00
set
2011-10-17 20:05:10 +00:00
2011-11-29 16:45:27 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-12-01 20:21:04 +00:00
2012-07-20 19:09:12 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-21 16:50:47 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-21 00:51:28 +00:00