[PATCH] D37241: [unittests] Add reverse iteration unit tests for pointer-like keys
Grang, Mandeep Singh via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 3 21:15:25 PDT 2017
> Hmm, I guess that works - hadn't considered that. Would this work if
the type in the container was PtrLikeInt instead of PtrLikeInt*? Seems
it might be a touch simpler.
I had tried PtrLikeInt but it seems it does not match any trait in
PointerLikeTypeTraits and hence is not considered pointer-like. Writing
a trait specialization for this seemed tedious and an overkill. Wasn't
sure how to implement the getAsVoidPointer. So I simply used PtrLikeInt*.
On 9/3/2017 5:20 PM, David Blaikie wrote:
>
>
> On Sun, Sep 3, 2017 at 12:06 AM Mandeep Singh Grang via Phabricator
> <reviews at reviews.llvm.org <mailto:reviews at reviews.llvm.org>> wrote:
>
> mgrang added inline comments.
>
>
> ================
> Comment at: unittests/Support/ReverseIterationTest.cpp:69
> +
> + static unsigned getHashValue(const PtrLikeInt *PtrVal) {
> + return (unsigned)(PtrVal->value * 37U);
> ----------------
> How about this implementation? PtrLikeInt is pointer-like but it
> hashes based on an integer value.
>
>
> Hmm, I guess that works - hadn't considered that. Would this work if
> the type in the container was PtrLikeInt instead of PtrLikeInt*? Seems
> it might be a touch simpler.
>
> I don't think this would work for SmallPtrSet (as you had pointed
> out).
>
>
>
> ================
> Comment at: unittests/Support/ReverseIterationTest.cpp:95
> + if (shouldReverseIterate<PtrLikeInt *>())
> + std::reverse(&IterKeys[0], &IterKeys[4]);
> +
> ----------------
> @dblaikie llvm::reverse(IterKeys) does not change the existing
> array, right?.
>
>
> Oh, right, sure.
>
> I found using std::reverse cleaner than using another array to
> hold the reversed one. What do you say?
>
>
> Fine as-is.
>
>
>
> Repository:
> rL LLVM
>
> https://reviews.llvm.org/D37241
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170903/65406527/attachment.html>
More information about the llvm-commits
mailing list