mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
bug 279844: Slow algorithm for checking duplicate path entries
This commit is contained in:
parent
67b658143c
commit
e69c7e2846
9 changed files with 83 additions and 31 deletions
|
@ -80,6 +80,16 @@ public abstract class APathEntry extends PathEntry {
|
|||
return this.fullCharExclusionPatterns;
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -40,6 +40,16 @@ public class IncludeFileEntry extends APathEntry implements IIncludeFileEntry {
|
|||
return includeFilePath;
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -44,6 +44,17 @@ public class MacroEntry extends APathEntry implements IMacroEntry {
|
|||
return macroValue;
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
@ -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()
|
||||
*/
|
||||
|
|
|
@ -39,6 +39,15 @@ public class MacroFileEntry extends APathEntry implements IMacroFileEntry {
|
|||
return macroFilePath;
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
|
|
@ -53,6 +53,16 @@ public class PathEntry implements IPathEntry {
|
|||
return isExported;
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue