From ec46f3182b684b41ae4348b013f50740cf1cd2b1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 22 Jan 2014 16:04:52 +0000 Subject: 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 --- llvm/lib/Object/ObjectFile.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Object/ObjectFile.cpp') diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp index fd2b024..6b14e78 100644 --- a/llvm/lib/Object/ObjectFile.cpp +++ b/llvm/lib/Object/ObjectFile.cpp @@ -37,9 +37,11 @@ section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const { return section_iterator(SectionRef(Sec, this)); } -ErrorOr ObjectFile::createObjectFile(MemoryBuffer *Object) { +ErrorOr ObjectFile::createObjectFile(MemoryBuffer *Object, + sys::fs::file_magic Type) { OwningPtr 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: -- cgit v1.1