[llvm-commits] [PATCH 09/20] [AVX] Make IntInit Unique
David A. Greene
dag at cray.com
Wed Jul 20 09:01:30 PDT 2011
Jakob Stoklund Olesen <stoklund at 2pi.dk> writes:
>> const IntInit *IntInit::get(int64_t V) {
>> - return new IntInit(V);
>> + typedef DenseMap<int64_t, IntInit *> Pool;
>> + static Pool ThePool;
>> +
>> + Pool::iterator Result = ThePool.find(V);
>> +
>> + if (Result == ThePool.end()) {
>> + IntInit *New = new IntInit(V);
>> + bool Inserted = false;
>> + tie(Result, Inserted) = ThePool.insert(std::make_pair(V, New));
>> + assert(Inserted && "Did not insert new Init into pool!");
>> + }
>> +
>> + return Result->second;
>> }
>
> This pattern is faster and simpler:
>
> const IntInit *&I = ThePool[V];
> if (!I) I = new IntInit(V);
> return I;
Ok.
-Dave
More information about the llvm-commits
mailing list