Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] 1_0_1 core/model fixes.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/ChangeLog,v
retrieving revision 1.54.2.1
diff -u -r1.54.2.1 ChangeLog
--- ChangeLog	6 Mar 2003 16:00:15 -0000	1.54.2.1
+++ ChangeLog	12 Mar 2003 21:01:27 -0000
@@ -1,5 +1,28 @@
 2003-03-06 Alain Magloire
 
+	A few corrections:  The Elf parser was call to often and unnecessarly.
+	We can optimized the code by holding on the IBinarFile object and reuse
+	it instead of calling isBinary(file), isArchive(file), isShared(file) 3 times,
+	getting IBinaryFile and calling IBinaryFile.getType() saves some call.
+	This also delays the creation of IBinaryInfo until needed.
+
+	* model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java
+	(addIfExec): Unused method removed.
+	* model/org/eclipse/cdt/internal/core/model/BinaryContainer.java
+	(addIfExec): Unused method removed.
+	(Visitor): Unused inner class removed.
+	* model/org/eclipse/cdt/internal/core/model/BinaryRunner:
+	Call the new method CModelManager.create(parent, file, binaryFile) instead.
+	and the create will add the binary to the container.
+	* model/org/eclipse/cdt/internal/core/model/CModelManager:
+	(getBinaryFile): New method.
+	(create): New method takes for argument the IBinaryFile if it was created.
+	* model/org/eclipse/cdt/internal/core/model/CProjectInfo
+	(getBinaryContainer): Now synchronized.
+	(getArchiveContainer): Now synchronized.
+
+2003-03-06 Alain Magloire
+
 	Overload isBinary()/isArchive()/isTranslationUnit()
 	* model/org/eclipse/cdt/internal/core/model/Archive.java:
 	* model/org/eclipse/cdt/internal/core/model/Binary.java:
Index: model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java,v
retrieving revision 1.5
diff -u -r1.5 ArchiveContainer.java
--- model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java	18 Nov 2002 15:44:49 -0000	1.5
+++ model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java	12 Mar 2003 21:01:27 -0000
@@ -59,18 +59,6 @@
 		return super.getChildren();
 	}
 
-	void addChildIfLib(IFile file) {
-		CModelManager factory = CModelManager.getDefault();
-		if (factory.isArchive(file)) {
-			ICElement celement = factory.create(file);
-			if (celement != null) {
-				if (celement instanceof IArchive) {
-					addChild (celement);
-				}
-			}
-		}
-	}
-
 	public CElementInfo createElementInfo() {
 		return new CElementInfo(this);
 	}
Index: model/org/eclipse/cdt/internal/core/model/BinaryContainer.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java,v
retrieving revision 1.5
diff -u -r1.5 BinaryContainer.java
--- model/org/eclipse/cdt/internal/core/model/BinaryContainer.java	18 Nov 2002 15:44:58 -0000	1.5
+++ model/org/eclipse/cdt/internal/core/model/BinaryContainer.java	12 Mar 2003 21:01:27 -0000
@@ -67,40 +67,7 @@
 		return super.getChildren();
 	}
 
-	void addChildIfExec(CoreModel factory, IFile file) {
-		// Attempt to speed things up by rejecting up front
-		// Things we know should not be Binary files.
-		if (!factory.isTranslationUnit(file)) {
-			ICElement celement = factory.create(file);
-			if (celement != null) {
-				if (celement instanceof IBinary) {
-					IBinary bin = (IBinary)celement;
-					if (bin.isExecutable() || bin.isSharedLib()) {
-						addChild (bin);
-					}
-				}
-			}
-		}
-	}
-
 	public CElementInfo createElementInfo() {
 		return new CElementInfo(this);
-	}
-
-	class Visitor implements IResourceVisitor {
-		CoreModel factory = CoreModel.getDefault();
-		BinaryContainer cbin;
-
-		public Visitor (BinaryContainer element) {
-			cbin = element;
-		}
-
-		public boolean visit(IResource res) throws CoreException {
-			if (res instanceof IFile) {
-				cbin.addChildIfExec(factory, (IFile)res);
-				return false;
-			}
-			return true;
-		}
 	}
 }
Index: model/org/eclipse/cdt/internal/core/model/BinaryRunner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java,v
retrieving revision 1.1
diff -u -r1.1 BinaryRunner.java
--- model/org/eclipse/cdt/internal/core/model/BinaryRunner.java	18 Nov 2002 15:45:46 -0000	1.1
+++ model/org/eclipse/cdt/internal/core/model/BinaryRunner.java	12 Mar 2003 21:01:27 -0000
@@ -5,26 +5,26 @@
  * All Rights Reserved.
  */
 
+import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICRoot;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IResourceVisitor;
 import org.eclipse.core.runtime.CoreException;
 
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.model.IArchive;
-import org.eclipse.cdt.core.model.IBinary;
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.ICRoot;
-
 public class BinaryRunner implements Runnable {
 	ArchiveContainer clib;
 	BinaryContainer cbin;
 	CProject cproject;
-
+	CModelManager factory;
+	
 	public BinaryRunner(CProject cprj) {
 		cproject = cprj;
 		cbin = (BinaryContainer)cprj.getBinaryContainer();
 		clib = (ArchiveContainer)cprj.getArchiveContainer();
+		factory = CModelManager.getDefault();
 	}
 
 	public void run() {
@@ -44,7 +44,6 @@
 		// Fired the event.
 		ICElement[] children = container.getChildren();
 		if (children.length > 0) {
-			CModelManager factory = CModelManager.getDefault();
 			ICElement root = (ICRoot)factory.getCRoot();
 			CElementDelta cdelta = new CElementDelta(root);
 			cdelta.added(cproject);
@@ -57,31 +56,21 @@
 		}
 	}
 
-	void addChildIfBinary(CoreModel factory, IFile file) {
+	void addChildIfBinary(IFile file) {
 		// Attempt to speed things up by rejecting up front
 		// Things we know should not be Binary files.
 		if (!factory.isTranslationUnit(file)) {
-			if (factory.isBinary(file)) {
-				ICElement celement = factory.create(file);
-				if (celement != null) {
-					if (celement instanceof IBinary) {
-						IBinary bin = (IBinary)celement;
-						if (bin.isExecutable() || bin.isSharedLib()) {
-							cbin.addChild(bin);
-						}
-					}
-				}
-			} else if (factory.isArchive(file)) {
-				ICElement celement = factory.create(file);
-				if (celement instanceof IArchive) {
-					clib.addChild(celement);
-				}
+			IBinaryFile bin = factory.getBinaryFile(file);
+			if (bin != null) {
+				IResource res = file.getParent();
+				ICElement parent = factory.create(res);
+				// By creating the element, it will be added to the correct (bin/archive)container.
+				factory.create(parent, file, bin);
 			}
 		}
 	}
 
 	class Visitor implements IResourceVisitor {
-		CoreModel factory = CoreModel.getDefault();
 		BinaryRunner runner;
 
 		public Visitor (BinaryRunner r) {
@@ -90,7 +79,7 @@
 
 		public boolean visit(IResource res) throws CoreException {
 			if (res instanceof IFile) {
-				runner.addChildIfBinary(factory, (IFile)res);
+				runner.addChildIfBinary((IFile)res);
 				return false;
 			}
 			return true;
Index: model/org/eclipse/cdt/internal/core/model/CModelManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java,v
retrieving revision 1.13
diff -u -r1.13 CModelManager.java
--- model/org/eclipse/cdt/internal/core/model/CModelManager.java	23 Jan 2003 16:40:04 -0000	1.13
+++ model/org/eclipse/cdt/internal/core/model/CModelManager.java	12 Mar 2003 21:01:27 -0000
@@ -183,13 +183,22 @@
 	}
 
 	public synchronized ICFile create(ICElement parent, IFile file) {
+		return create(parent, file, null);
+	}
+
+	public ICFile create(ICElement parent, IFile file, IBinaryFile bin) {
 		ICFile cfile = (ICFile)fParsedResources.get(file);
 		if (cfile == null) {
 			if (file.exists()) {
-				if (isArchive(file)) {
-					cfile = new Archive(parent, file);
-				} else if (isBinary(file)) {
-					cfile = new Binary(parent, file);
+				if (bin == null) {
+					bin = getBinaryFile(file);
+				}
+				if (bin != null) {
+					if (bin.getType() == IBinaryFile.ARCHIVE) {
+						cfile = new Archive(parent, file);
+					} else {
+						cfile = new Binary(parent, file);
+					}
 				} else if (isTranslationUnit(file)) {
 					cfile = new TranslationUnit(parent, file);
 				} else {
@@ -199,23 +208,23 @@
 			}
 		}
 		// Added also to the Containers
-		if (cfile != null) {
-			if (cfile instanceof IArchive) {
+		if (cfile != null && (cfile instanceof IBinary || cfile instanceof IArchive)) {
+			if (bin == null) {
+				bin = getBinaryFile(file);
+			}
+			if (bin.getType() == IBinaryFile.ARCHIVE) {
 				CProject cproj = (CProject)cfile.getCProject();
 				ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer();
 				container.addChild(cfile);
-			} else if (cfile instanceof IBinary) {
-				IBinary bin = (IBinary)cfile;
-				if (bin.isExecutable() || bin.isSharedLib()) {
-					CProject cproj = (CProject)cfile.getCProject();
-					BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer();
-					container.addChild(bin);
-				}
+			} else if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) {
+				CProject cproj = (CProject)cfile.getCProject();
+				BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer();
+				container.addChild(cfile);
 			}
 		}
 		return cfile;
 	}
-
+	
 	public ICFolder create(IFolder folder) {
 		IResource parent = folder.getParent();
 		ICElement cparent = null;
@@ -491,6 +500,17 @@
 		return false;
 	}
 
+	public IBinaryFile getBinaryFile(IFile file) {
+		IBinaryFile bin = null;
+		try {
+			IBinaryParser parser = getBinaryParser(file.getProject());
+			bin = parser.getBinary(file);
+		} catch (IOException e) {
+			//e.printStackTrace();
+		}
+		return bin;
+	}
+	
 	public boolean isBinary(IFile file) {
 		try {
 			IBinaryParser parser = getBinaryParser(file.getProject());
Index: model/org/eclipse/cdt/internal/core/model/CProjectInfo.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java,v
retrieving revision 1.1
diff -u -r1.1 CProjectInfo.java
--- model/org/eclipse/cdt/internal/core/model/CProjectInfo.java	26 Jun 2002 20:37:14 -0000	1.1
+++ model/org/eclipse/cdt/internal/core/model/CProjectInfo.java	12 Mar 2003 21:01:27 -0000
@@ -18,7 +18,7 @@
 	private BinaryContainer vBin;
 	private ArchiveContainer vLib;
 
-	public IBinaryContainer getBinaryContainer() {
+	synchronized public IBinaryContainer getBinaryContainer() {
 		if (vBin == null) {
 			vBin = new BinaryContainer((CProject)getElement());
 			addChild(vBin);
@@ -26,7 +26,7 @@
 		return vBin;
 	}
 
-	public IArchiveContainer getArchiveContainer() {
+	synchronized public IArchiveContainer getArchiveContainer() {
 		if (vLib == null) {
 			vLib = new ArchiveContainer((CProject)getElement());
 			addChild(vLib);



Back to the top