This is an archive of the discontinued LLVM Phabricator instance.

[Object, MachO] Cache parsed MachO header in MachOObjectFile. NFC.
ClosedPublic

Authored by samsonov on Jun 3 2015, 4:11 PM.

Details

Summary

Avoid parsing object file each time MachOObjectFile::getHeader() is
called. Instead, cache the header in MachOObjectFile constructor, where
it's parsed anyway. In future, we must avoid constructing the object
at all if the header can't be parsed.

Diff Detail

Event Timeline

samsonov updated this revision to Diff 27070.Jun 3 2015, 4:11 PM
samsonov retitled this revision from to [Object, MachO] Cache parsed MachO header in MachOObjectFile. NFC..
samsonov updated this object.
samsonov edited the test plan for this revision. (Show Details)
samsonov added a reviewer: rafael.
samsonov added a subscriber: Unknown Object (MLST).
filcab added a subscriber: filcab.Jun 3 2015, 4:50 PM

LGTM.

I'd probably like a comment pointing out that it works because all the (used) members of mach_header and mach_header64 match in size and location.
For people reading the code who aren't familiar with how those headers look, the MachOObjectFile constructor might look weird. (Not a strong want, but I think it might help readability)

Thanks

We may get rid of Header pointer completely, and instead put this logic (with an appropriate comment) in getHeader() method. Let me know what you prefer.

Submitted in r239075 (messed with branches, so Phabricator didn't close it for some reason).

samsonov accepted this revision.Jun 4 2015, 12:40 PM
samsonov added a reviewer: samsonov.
This revision is now accepted and ready to land.Jun 4 2015, 12:40 PM
samsonov closed this revision.Jun 4 2015, 12:40 PM