From: Richard Smith Date: Thu, 14 Apr 2016 19:45:19 +0000 (+0000) Subject: Make this code less brittle. The benefits of a fixed-size array aren't worth the... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f054cc1bddf40f4874dec7da7cb18d67db80390b;p=clang Make this code less brittle. The benefits of a fixed-size array aren't worth the maintenance cost. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266359 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index a5915e7c7e..c1ec38c889 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -704,13 +704,10 @@ class ASTRecordWriter { /// declaration or type. SmallVector StmtsToEmit; - /// Worst case: bases, vbases, visible and lexical contents, local redecls. - static const int MaxOffsetIndices = 5; /// \brief Indices of record elements that describe offsets within the /// bitcode. These will be converted to offsets relative to the current /// record when emitted. - unsigned OffsetIndices[MaxOffsetIndices]; - unsigned NumOffsetIndices = 0; + SmallVector OffsetIndices; /// \brief Flush all of the statements and expressions that have /// been added to the queue via AddStmt(). @@ -719,13 +716,13 @@ class ASTRecordWriter { void PrepareToEmit(uint64_t MyOffset) { // Convert offsets into relative form. - for (unsigned I = 0; I != NumOffsetIndices; ++I) { - auto &StoredOffset = (*Record)[OffsetIndices[I]]; + for (unsigned I : OffsetIndices) { + auto &StoredOffset = (*Record)[I]; assert(StoredOffset < MyOffset && "invalid offset"); if (StoredOffset) StoredOffset = MyOffset - StoredOffset; } - NumOffsetIndices = 0; + OffsetIndices.clear(); } public: @@ -779,8 +776,7 @@ public: /// \brief Add a bit offset into the record. This will be converted into an /// offset relative to the current record when emitted. void AddOffset(uint64_t BitOffset) { - assert(NumOffsetIndices != MaxOffsetIndices && "too many offset indices"); - OffsetIndices[NumOffsetIndices++] = Record->size(); + OffsetIndices.push_back(Record->size()); Record->push_back(BitOffset); }