llvm.org GIT mirror llvm / d3ca239
Don't store a Child to the first regular member. This is a bit ugly, but has a few advantages: * Archive is now easy to copy since there is no Archive -> Child -> Archive loop. * It makes it clear that we already checked for errors when finding the Child data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251750 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
2 changed file(s) with 24 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
5151 virtual void anchor();
5252 public:
5353 class Child {
54 friend Archive;
5455 const Archive *Parent;
5556 /// \brief Includes header but not padding byte.
5657 StringRef Data;
6566
6667 public:
6768 Child(const Archive *Parent, const char *Start);
69 Child(const Archive *Parent, StringRef Data, uint16_t StartOfFile);
6870
6971 bool operator ==(const Child &other) const {
7072 assert(Parent == other.Parent);
205207 private:
206208 StringRef SymbolTable;
207209 StringRef StringTable;
208 child_iterator FirstRegular;
210
211 StringRef FirstRegularData;
212 uint16_t FirstRegularStartOfFile = -1;
213 void setFirstRegular(const Child &C);
214
209215 unsigned Format : 2;
210216 unsigned IsThin : 1;
211217 mutable std::vector> ThinBuffers;
8080 llvm_unreachable("GID time not a decimal number.");
8181 return Ret;
8282 }
83
84 Archive::Child::Child(const Archive *Parent, StringRef Data,
85 uint16_t StartOfFile)
86 : Parent(Parent), Data(Data), StartOfFile(StartOfFile) {}
8387
8488 Archive::Child::Child(const Archive *Parent, const char *Start)
8589 : Parent(Parent) {
231235 return std::move(Ret);
232236 }
233237
238 void Archive::setFirstRegular(const Child &C) {
239 FirstRegularData = C.Data;
240 FirstRegularStartOfFile = C.StartOfFile;
241 }
242
234243 Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
235 : Binary(Binary::ID_Archive, Source), FirstRegular(child_end()) {
244 : Binary(Binary::ID_Archive, Source) {
236245 StringRef Buffer = Data.getBuffer();
237246 // Check for sufficient magic.
238247 if (Buffer.startswith(ThinMagic)) {
280289 // there is no error.
281290 SymbolTable = *i->getBuffer();
282291 ++i;
283 FirstRegular = i;
292 setFirstRegular(*i);
284293 ec = std::error_code();
285294 return;
286295 }
299308 SymbolTable = *i->getBuffer();
300309 ++i;
301310 }
302 FirstRegular = i;
311 setFirstRegular(*i);
303312 return;
304313 }
305314
330339 // ErrorOr.
331340 StringTable = *i->getBuffer();
332341 ++i;
333 FirstRegular = i;
342 setFirstRegular(*i);
334343 ec = std::error_code();
335344 return;
336345 }
337346
338347 if (Name[0] != '/') {
339348 Format = has64SymTable ? K_MIPS64 : K_GNU;
340 FirstRegular = i;
349 setFirstRegular(*i);
341350 ec = std::error_code();
342351 return;
343352 }
354363
355364 ++i;
356365 if (i == e) {
357 FirstRegular = i;
366 setFirstRegular(*i);
358367 ec = std::error_code();
359368 return;
360369 }
368377 ++i;
369378 }
370379
371 FirstRegular = i;
380 setFirstRegular(*i);
372381 ec = std::error_code();
373382 }
374383
377386 return child_end();
378387
379388 if (SkipInternal)
380 return FirstRegular;
389 return Child(this, FirstRegularData, FirstRegularStartOfFile);
381390
382391 const char *Loc = Data.getBufferStart() + strlen(Magic);
383392 Child c(this, Loc);