@@ -625,11 +625,66 @@ class SourceManager : public RefCountedBase<SourceManager> {
625625 // / expansion.
626626 SmallVector<SrcMgr::SLocEntry, 0 > LocalSLocEntryTable;
627627
628+ template <typename T, unsigned ChunkSize>
629+ class SparseVector {
630+ typedef std::array<T, ChunkSize> Chunk;
631+ std::vector<Chunk*> Chunks;
632+ std::size_t realSize = 0 ;
633+ std::size_t allocatedChunks = 0 ;
634+
635+ Chunk *getChunk (std::size_t i) {
636+ std::size_t ChunkIndex = i / ChunkSize;
637+
638+ Chunk* Result = Chunks.at (ChunkIndex);
639+ if (Result == nullptr ) {
640+ Result = new Chunk ();
641+ Chunks[ChunkIndex] = Result;
642+ allocatedChunks++;
643+ }
644+ return Result;
645+ }
646+ public:
647+ SparseVector () {
648+ }
649+
650+ typedef T value_type;
651+
652+ T& operator [](std::size_t i) {
653+ Chunk *C = getChunk (i);
654+ std::size_t Rem = i % ChunkSize;
655+ return (*C)[Rem];
656+ }
657+
658+ std::size_t size () const {
659+ return realSize;
660+ }
661+
662+ std::size_t capacity () const {
663+ return allocatedChunks * ChunkSize;
664+ }
665+
666+ void resize (std::size_t s) {
667+ realSize = s;
668+ Chunks.resize ((s / ChunkSize) + 1 );
669+ }
670+
671+ void clear () {
672+ Chunks.clear ();
673+ realSize = 0 ;
674+ allocatedChunks = 0 ;
675+ }
676+
677+ bool empty () const {
678+ return realSize == 0 ;
679+ }
680+ };
681+
628682 // / \brief The table of SLocEntries that are loaded from other modules.
629683 // /
630684 // / Negative FileIDs are indexes into this table. To get from ID to an index,
631685 // / use (-ID - 2).
632- mutable SmallVector<SrcMgr::SLocEntry, 0 > LoadedSLocEntryTable;
686+ mutable SparseVector<SrcMgr::SLocEntry, 4096 > LoadedSLocEntryTable;
687+ // mutable SmallVector<SrcMgr::SLocEntry, 0> LoadedSLocEntryTable;
633688
634689 // / \brief The starting offset of the next local SLocEntry.
635690 // /
0 commit comments