diff options
author | Kostya Serebryany <kcc@google.com> | 2016-01-21 01:52:14 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-01-21 01:52:14 +0000 |
commit | 2f13f223c7a997a5dc6c67a70050260d13d56f5c (patch) | |
tree | 134f3ec133b7979e991c849407be07924e7f7dcb /llvm/lib | |
parent | a7a8ab71aa2f428ba5f71776e5c9656c5cd7d1f9 (diff) | |
download | bcm5719-llvm-2f13f223c7a997a5dc6c67a70050260d13d56f5c.tar.gz bcm5719-llvm-2f13f223c7a997a5dc6c67a70050260d13d56f5c.zip |
[libFuzzer] don't use std::vector in one more hot path
llvm-svn: 258380
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerMutate.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerMutate.cpp b/llvm/lib/Fuzzer/FuzzerMutate.cpp index 69680c8a1a4..4197df9e4e2 100644 --- a/llvm/lib/Fuzzer/FuzzerMutate.cpp +++ b/llvm/lib/Fuzzer/FuzzerMutate.cpp @@ -27,13 +27,35 @@ struct DictionaryEntry { size_t PositionHint; }; -struct Dictionary : public std::vector<DictionaryEntry>{ +class Dictionary { + public: + static const size_t kMaxDictSize = 1 << 14; + bool ContainsWord(const Word &W) const { return std::any_of(begin(), end(), [&](const DictionaryEntry &DE) { return DE.W == W; }); } + const DictionaryEntry *begin() const { return &DE[0]; } + const DictionaryEntry *end() const { return begin() + Size; } + const DictionaryEntry & operator[] (size_t Idx) const { + assert(Idx < Size); + return DE[Idx]; + } + void push_back(DictionaryEntry DE) { + if (Size < kMaxDictSize) + this->DE[Size++] = DE; + } + void clear() { Size = 0; } + bool empty() const { return Size == 0; } + size_t size() const { return Size; } + +private: + DictionaryEntry DE[kMaxDictSize]; + size_t Size = 0; }; +const size_t Dictionary::kMaxDictSize; + struct MutationDispatcher::Impl { // Dictionary provided by the user via -dict=DICT_FILE. Dictionary ManualDictionary; @@ -67,8 +89,8 @@ struct MutationDispatcher::Impl { "AddFromPersAutoDict"}); } void SetCorpus(const std::vector<Unit> *Corpus) { this->Corpus = Corpus; } - size_t AddWordFromDictionary(const std::vector<DictionaryEntry> &D, - uint8_t *Data, size_t Size, size_t MaxSize); + size_t AddWordFromDictionary(const Dictionary &D, uint8_t *Data, size_t Size, + size_t MaxSize); }; static char FlipRandomBit(char X, FuzzerRandomBase &Rand) { @@ -154,9 +176,10 @@ size_t MutationDispatcher::Mutate_AddWordFromPersistentAutoDictionary( MaxSize); } -size_t MutationDispatcher::Impl::AddWordFromDictionary( - const std::vector<DictionaryEntry> &D, uint8_t *Data, size_t Size, - size_t MaxSize) { +size_t MutationDispatcher::Impl::AddWordFromDictionary(const Dictionary &D, + uint8_t *Data, + size_t Size, + size_t MaxSize) { if (D.empty()) return 0; const DictionaryEntry &DE = D[Rand(D.size())]; const Word &W = DE.W; |