[PATCH] [libcxx] Fix __is_power2 and __next_power2. Change hashmap to handle new behavior.

Eric Fiselier eric at efcs.ca
Thu Oct 2 11:42:39 PDT 2014


> If this isn't/wasn't going to help out the PMF stuff in std::experimental, then I don't think that this is worth doing.

I agree, I think the best thing to do would be to simply rename the functions to avoid name collisions and then implement them separately for the PMR stuff. That way we don't have to worry about changing the performance of the hash containers.

================
Comment at: include/__hash_table:86
@@ -79,2 +85,3 @@
 {
-    return size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
+    return __n < 2 ? __n + (__n == 0)
+        : size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
----------------
mclow.lists wrote:
> Looks to me that this produces:
> 0 --> 1
> 1 --> 1
> 2 --> 4
> 4 --> 8
> 
> Is that the intended behavior? (especially the second one)
Oops, I don't think so. 
```
return n < 2 ? __n + 1 
```
Should fix that. 

But IDK if the change is needed. However I am still concerned that the current version exhibits undefined behaviour for `__n = 1`.

http://reviews.llvm.org/D4948






More information about the cfe-commits mailing list