Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java')
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java47
1 files changed, 45 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java
index b3c4679ab65..8a25bb812c3 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/ElfParser.java
@@ -22,6 +22,9 @@ import org.eclipse.core.runtime.IPath;
/**
*/
public class ElfParser extends AbstractCExtension implements IBinaryParser {
+ byte [] fCachedByteArray;
+ IPath fCachedPathEntry;
+ boolean fCachedIsAR;
/**
* @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IPath)
@@ -33,7 +36,30 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
BinaryFile binary = null;
try {
- Elf.Attribute attribute = Elf.getAttributes(path.toOSString());
+ Elf.Attribute attribute = null;
+
+ //Try our luck with the cached entry first, then clear it
+ if(fCachedPathEntry != null && fCachedPathEntry.equals(path)) {
+ try {
+ //Don't bother with ELF stuff if this is an archive
+ if(fCachedIsAR) {
+ return new BinaryArchive(path);
+ }
+ //Well, if it wasn't an archive, go for broke
+ attribute = Elf.getAttributes(fCachedByteArray);
+ } catch(Exception ex) {
+ attribute = null;
+ } finally {
+ fCachedPathEntry = null;
+ fCachedByteArray = null;
+ }
+ }
+
+ //Take a second run at it if the cache failed.
+ if(attribute == null) {
+ attribute = Elf.getAttributes(path.toOSString());
+ }
+
if (attribute != null) {
switch (attribute.getType()) {
case Attribute.ELF_TYPE_EXE :
@@ -72,7 +98,24 @@ public class ElfParser extends AbstractCExtension implements IBinaryParser {
* @see org.eclipse.cdt.core.IBinaryParser#isBinary(byte[], org.eclipse.core.runtime.IPath)
*/
public boolean isBinary(byte[] array, IPath path) {
- return Elf.isElfHeader(array) || AR.isARHeader(array);
+ boolean isBinaryReturnValue = false;
+
+ if(Elf.isElfHeader(array)) {
+ isBinaryReturnValue = true;
+ fCachedIsAR = false;
+ } else if(AR.isARHeader(array)) {
+ isBinaryReturnValue = true;
+ fCachedIsAR = true;
+ }
+
+ //If it is a binary, then cache the array in anticipation that we will be asked to do something with it
+ if(isBinaryReturnValue && array.length > 0) {
+ fCachedPathEntry = path;
+ fCachedByteArray = new byte[array.length];
+ System.arraycopy(array, 0, fCachedByteArray, 0, array.length);
+ }
+
+ return isBinaryReturnValue;
}
}

Back to the top