Skip to content

Commit 065a25f

Browse files
authored
Reserve AllDelayed vector to upper bound.
File: [swift/lib/Parse/PersistentParserState.cpp] Observing this code snipped closely in function, [void PersistentParserState::parseAllDelayedDeclLists()]: ``` for (auto &P: DelayedDeclListStates) { AllDelayed.push_back(P.first); } ``` We observe that 'AllDelayed' gets maximum of DelayedDeclListStates.size() elements pushed into it. So it is better to reserve 'vector AllDelayed' to that max size, to save reallocation cost. I believe we can use size() on [DelayedDeclListStates], which is of type: ```llvm::DenseMap<IterableDeclContext *, std::unique_ptr<DelayedDeclListState>>``` because of the ```DenseMapIterator``` implementation of size(). [http://llvm.org/doxygen/DenseMap_8h_source.html#l00126]
1 parent 7a383f4 commit 065a25f

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/Parse/PersistentParserState.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ void PersistentParserState::delayDeclList(IterableDeclContext* D,
8383

8484
void PersistentParserState::parseAllDelayedDeclLists() {
8585
std::vector<IterableDeclContext*> AllDelayed;
86+
AllDelayed.reserve(DelayedDeclListStates.size());
8687
for (auto &P: DelayedDeclListStates) {
8788
AllDelayed.push_back(P.first);
8889
}

0 commit comments

Comments
 (0)