Skip to content

Commit

Permalink
Event: made copy operator pull from entry store when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
decibelcooper committed May 11, 2019
1 parent 16ceb12 commit a4d0d06
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,31 @@ void Event::UseGeneratedPool(bool useGenPool) {

Event &Event::operator=(const Event &event) {
if (&event == this) return *this;
Clear();
*this->eventProto = *event.eventProto;
this->revTypeLookup = event.revTypeLookup;
this->descriptorCache = event.descriptorCache;
for (auto idEntryPair : event.entryCache) {
auto entry = idEntryPair.second;
const Descriptor *desc = getDescriptor(getTypeID(entry));
if (!desc) throw unknownMessageTypeError;
auto newEntry = MessageFactory::generated_factory()->GetPrototype(desc)->New();
Message *newEntry;
std::vector<Message *> &storeEntries = store[desc];
if (storeEntries.size() > 0) {
newEntry = storeEntries.back();
storeEntries.pop_back();
} else {
const Message *prototype = NULL;
if (useGenPool) prototype = MessageFactory::generated_factory()->GetPrototype(desc);
if (!prototype && messageFactory) prototype = messageFactory->GetPrototype(desc);
if (prototype)
newEntry = prototype->New();
else
throw unknownMessageTypeError;
}
newEntry->MergeFrom(*entry);
this->entryCache[idEntryPair.first] = newEntry;
}
this->descriptorCache = event.descriptorCache;
this->metadata = event.metadata;
this->dirtyTags = event.dirtyTags;
return *this;
Expand Down

0 comments on commit a4d0d06

Please sign in to comment.