[llvm] r206857 - blockfreq: Use pointers to loops instead of an index
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Apr 24 21:40:41 PDT 2014
On 2014-Apr-21, at 21:42, David Blaikie <dblaikie at gmail.com> wrote:
> On Mon, Apr 21, 2014 at 9:39 PM, David Blaikie <dblaikie at gmail.com> wrote:
>> On Mon, Apr 21, 2014 at 8:31 PM, Duncan P. N. Exon Smith
>> <dexonsmith at apple.com> wrote:
>>> Author: dexonsmith
>>> Date: Mon Apr 21 22:31:37 2014
>>> New Revision: 206857
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=206857&view=rev
>>> Log:
>>> blockfreq: Use pointers to loops instead of an index
>>>
>>> Store pointers directly to loops inside the nodes. This could have been
>>> done without changing the type stored in `std::vector<>`. However,
>>> rather than computing the number of loops before constructing them
>>> (which `LoopInfo` doesn't provide directly), I've switched to a
>>> `vector<unique_ptr<LoopData>>`.
>>
>> Why not use a std::list<LoopData>? If you're going to incur a heap
>> allocation for every node anyway, this at least hides it as an
>> implementation detail (& you can include a comment explaining that
>> you're taking pointers to these things and so you need the iterator
>> (non)invalidation semantics of list over vector)
>>
>> I've made a change from vector<(owning)T*> to list<T> in one or two
>> places today for just this reason.
>
> (or perhaps a std::deque - which I hadn't considered before, but works
> since I (& you, I think) don't need validity of pointers over removal
> operations - just additions at the end)
You're right, no benefit to std::vector<> here. Went with std::list<> in r207177.
More information about the llvm-commits
mailing list