Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gvozdev2009-09-01 18:16:28 -0400
committerAndrew Gvozdev2009-09-01 18:16:28 -0400
commitb996a21d7dfb60680216bbe355010d98d03fe299 (patch)
tree0d4cc2f81f7a27149dd2bdc449222c4cfc45d6a5
parent606c6f3cb2d0b38d945b64da207b58588354fbde (diff)
downloadorg.eclipse.cdt-b996a21d7dfb60680216bbe355010d98d03fe299.tar.gz
org.eclipse.cdt-b996a21d7dfb60680216bbe355010d98d03fe299.tar.xz
org.eclipse.cdt-b996a21d7dfb60680216bbe355010d98d03fe299.zip
bug 279844: Slow algorithm for checking duplicate path entries
Patch from David Dubrow
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java21
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java10
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeFileEntry.java10
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java10
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java16
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroFileEntry.java9
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java15
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryUtil.java21
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties2
9 files changed, 83 insertions, 31 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java
index ffde394f52..a6c0192617 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java
@@ -81,6 +81,16 @@ public abstract class APathEntry extends PathEntry {
}
@Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((basePath == null) ? 0 : basePath.hashCode());
+ result = prime * result + ((baseRef == null) ? 0 : baseRef.hashCode());
+ result = prime * result + Arrays.hashCode(exclusionPatterns);
+ return result;
+ }
+
+ @Override
public boolean equals(Object obj) {
if (obj instanceof APathEntry) {
APathEntry otherEntry = (APathEntry)obj;
@@ -125,16 +135,6 @@ public abstract class APathEntry extends PathEntry {
return super.equals(obj);
}
- @Override
- public int hashCode() {
- int hashCode = Arrays.hashCode(exclusionPatterns);
- if (basePath != null)
- hashCode += basePath.hashCode();
- if (baseRef != null)
- hashCode += baseRef.hashCode();
- return hashCode + super.hashCode();
- }
-
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -150,4 +150,5 @@ public abstract class APathEntry extends PathEntry {
}
return sb.toString();
}
+
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java
index 0ddc10cfe2..ef67870db4 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java
@@ -49,6 +49,16 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry {
return isSystemInclude;
}
+@Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((includePath == null) ? 0 : includePath.hashCode());
+ result = prime * result + (isSystemInclude ? 1231 : 1237);
+ return result;
+ }
+
@Override
public boolean equals(Object obj) {
if (obj instanceof IIncludeEntry) {
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeFileEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeFileEntry.java
index 5e4cd59048..e9faac8897 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeFileEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeFileEntry.java
@@ -41,6 +41,16 @@ public class IncludeFileEntry extends APathEntry implements IIncludeFileEntry {
}
@Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((includeFilePath == null) ? 0 : includeFilePath.hashCode());
+ return result;
+ }
+
+
+ @Override
public boolean equals(Object obj) {
if (obj instanceof IIncludeFileEntry) {
IIncludeFileEntry otherEntry = (IIncludeFileEntry) obj;
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java
index 489ea932bb..927189b71a 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java
@@ -90,6 +90,16 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
return sourceAttachmentPrefixMapping;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((libraryPath == null) ? 0 : libraryPath.hashCode());
+ result = prime * result + ((sourceAttachmentPath == null) ? 0 : sourceAttachmentPath.hashCode());
+ result = prime * result
+ + ((sourceAttachmentRootPath == null) ? 0 : sourceAttachmentRootPath.hashCode());
+ return result;
+ }
@Override
public boolean equals(Object obj) {
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java
index b72fde1873..0da0320444 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java
@@ -45,6 +45,17 @@ public class MacroEntry extends APathEntry implements IMacroEntry {
}
@Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((macroName == null) ? 0 : macroName.hashCode());
+ result = prime * result
+ + ((macroValue == null) ? 0 : macroValue.hashCode());
+ return result;
+ }
+
+ @Override
public boolean equals(Object obj) {
if (obj instanceof IMacroEntry) {
IMacroEntry otherEntry = (IMacroEntry)obj;
@@ -74,11 +85,6 @@ public class MacroEntry extends APathEntry implements IMacroEntry {
return super.equals(obj);
}
- @Override
- public int hashCode() {
- return macroName.hashCode() + macroValue.hashCode() + super.hashCode();
- }
-
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroFileEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroFileEntry.java
index 59f8466f2b..822643da07 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroFileEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroFileEntry.java
@@ -40,6 +40,15 @@ public class MacroFileEntry extends APathEntry implements IMacroFileEntry {
}
@Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((macroFilePath == null) ? 0 : macroFilePath.hashCode());
+ return result;
+ }
+
+ @Override
public boolean equals(Object obj) {
if (obj instanceof IMacroFileEntry) {
IMacroFileEntry otherEntry = (IMacroFileEntry) obj;
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java
index dbb6d3bb14..8cdb037fe6 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java
@@ -54,6 +54,16 @@ public class PathEntry implements IPathEntry {
}
@Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + entryKind;
+ result = prime * result + (isExported ? 1231 : 1237);
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
public boolean equals(Object obj) {
if (obj instanceof IPathEntry) {
IPathEntry otherEntry = (IPathEntry)obj;
@@ -71,11 +81,6 @@ public class PathEntry implements IPathEntry {
return super.equals(obj);
}
- @Override
- public int hashCode() {
- return path.hashCode() + entryKind * 17 + (isExported ? 3 : 2);
- }
-
/**
* Returns the kind from its <code>String</code> form.
*/
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryUtil.java
index 5ef070b713..26299597bc 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryUtil.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryUtil.java
@@ -12,9 +12,12 @@
package org.eclipse.cdt.internal.core.model;
import java.io.File;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
@@ -335,17 +338,15 @@ public class PathEntryUtil {
public static ICModelStatus validatePathEntry(ICProject cProject, IPathEntry[] entries) {
// Check duplication.
+ Set<IPathEntry> entrySet = new HashSet<IPathEntry>(entries.length);
for (IPathEntry entry : entries) {
- if (entry == null) {
- continue;
- }
- for (IPathEntry otherEntry : entries) {
- if (otherEntry == null) {
- continue;
- }
- if (entry != otherEntry && otherEntry.equals(entry)) {
- StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$
- return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString());
+ if (entry != null) {
+ if (entrySet.contains(entry)) {
+ return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY,
+ MessageFormat.format(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry"), //$NON-NLS-1$
+ entry, entry.getPath()));
+ } else {
+ entrySet.add(entry);
}
}
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties
index 104221df17..e187a76d9b 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties
@@ -22,7 +22,7 @@ CoreModel.NullBinaryParser.Not_binary_file=not a binary file
CoreModel.NullBinaryParser.Null_Format=Null Format
CoreModel.PathEntry.IllegalContainerPath= Illegal container entry
-CoreModel.PathEntry.DuplicateEntry= Duplicate path entries
+CoreModel.PathEntry.DuplicateEntry= Duplicate path entries found ({0}), path: [{1}]
CoreModel.PathEntry.NestedEntry= Nested path entries
CoreModel.PathEntry.InvalidPathEntry= Invalid path

Back to the top