Pass the computed magic to createBinary and createObjectFile if available.

identify_magic is not free, so we should avoid calling it twice. The argument
also makes it cheap for createBinary to just forward to createObjectFile.

llvm-svn: 199813
This commit is contained in:
Rafael Espindola
2014-01-22 16:04:52 +00:00
parent 7a7c192e3e
commit ec46f3182b
5 changed files with 25 additions and 17 deletions

View File

@@ -37,9 +37,11 @@ section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const {
return section_iterator(SectionRef(Sec, this));
}
ErrorOr<ObjectFile *> ObjectFile::createObjectFile(MemoryBuffer *Object) {
ErrorOr<ObjectFile *> ObjectFile::createObjectFile(MemoryBuffer *Object,
sys::fs::file_magic Type) {
OwningPtr<MemoryBuffer> ScopedObj(Object);
sys::fs::file_magic Type = sys::fs::identify_magic(Object->getBuffer());
if (Type == sys::fs::file_magic::unknown)
Type = sys::fs::identify_magic(Object->getBuffer());
switch (Type) {
case sys::fs::file_magic::unknown: