diff options
author | Ed Merks | 2015-11-20 09:26:06 +0000 |
---|---|---|
committer | Thomas Watson | 2015-12-01 15:27:34 +0000 |
commit | 18ce78ca78bcf8239b3325c850e75de5d32353d5 (patch) | |
tree | 75cc109768543794d1ced840523c84e1043b3ec2 | |
parent | 2ed8a30003a6d69ee0fa3fd89314a40e4637b528 (diff) | |
download | rt.equinox.framework-18ce78ca78bcf8239b3325c850e75de5d32353d5.tar.gz rt.equinox.framework-18ce78ca78bcf8239b3325c850e75de5d32353d5.tar.xz rt.equinox.framework-18ce78ca78bcf8239b3325c850e75de5d32353d5.zip |
Bug 482643 The performance of FilterImpl.matches(Map) can be improved.I20151203-1230I20151203-0800I20151201-1100
Change-Id: I7d0f1697f17fafd93cd92aad089e67ac6ea17398
Signed-off-by: Ed Merks <ed.merks@gmail.com>
-rw-r--r-- | bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java | 63 | ||||
-rw-r--r-- | bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java | 28 |
2 files changed, 83 insertions, 8 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java index 4e012d889..15cbe5641 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java @@ -124,7 +124,7 @@ import org.osgi.framework.*; * data type will evaluate to <code>false</code> . */ -public class FilterImpl implements Filter /* since Framework 1.1 */{ +public class FilterImpl implements Filter /* since Framework 1.1 */ { /* public methods in org.osgi.framework.Filter */ /** @@ -384,9 +384,9 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{ String[] substrings = (String[]) value; for (String substr : substrings) { - if (substr == null) /* * */{ + if (substr == null) /* * */ { sb.append('*'); - } else /* xxx */{ + } else /* xxx */ { sb.append(encodeValue(substr)); } } @@ -549,6 +549,10 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{ return compare_String(operation, (String) value1, value2); } + if (value1 instanceof Version) { + return compare_Version(operation, (Version) value1, value2); + } + Class<?> clazz = value1.getClass(); if (clazz.isArray()) { Class<?> type = clazz.getComponentType(); @@ -725,8 +729,8 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{ for (int i = 0, size = substrings.length; i < size; i++) { String substr = substrings[i]; - if (i + 1 < size) /* if this is not that last substr */{ - if (substr == null) /* * */{ + if (i + 1 < size) /* if this is not that last substr */ { + if (substr == null) /* * */ { String substr2 = substrings[i + 1]; if (substr2 == null) /* ** */ @@ -743,7 +747,7 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{ pos = index + substr2.length(); if (i + 2 < size) // if there are more substrings, increment over the string we just matched; otherwise need to do the last substr check i++; - } else /* xxx */{ + } else /* xxx */ { int len = substr.length(); if (debug) { @@ -755,8 +759,8 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{ return false; } } - } else /* last substr */{ - if (substr == null) /* * */{ + } else /* last substr */ { + if (substr == null) /* * */ { return true; } /* xxx */ @@ -1197,6 +1201,49 @@ public class FilterImpl implements Filter /* since Framework 1.1 */{ } } + private boolean compare_Version(int operation, Version value1, Object value2) { + if (operation == SUBSTRING) { + if (debug) { + Debug.println("SUBSTRING(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + return false; + } + try { + Version version = Version.valueOf(((String) value2).trim()); + + switch (operation) { + case EQUAL : { + if (debug) { + Debug.println("EQUAL(" + value1 + "," + value + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + return value1.equals(version); + } + case APPROX : { + if (debug) { + Debug.println("APPROX(" + value1 + "," + value + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + return value1.equals(version); + } + case GREATER : { + if (debug) { + Debug.println("GREATER(" + value1 + "," + value + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + return value1.compareTo(version) >= 0; + } + case LESS : { + if (debug) { + Debug.println("LESS(" + value1 + "," + value + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + return value1.compareTo(version) <= 0; + } + } + } catch (Exception e) { + // if the valueOf or compareTo method throws an exception + return false; + } + return false; + } + private boolean compare_Comparable(int operation, Comparable<Object> value1, Object value2) { if (operation == SUBSTRING) { if (debug) { diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java index e93d15cef..d0ff36f16 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/FrameworkUtil.java @@ -734,6 +734,9 @@ public class FrameworkUtil { if (value1 instanceof String) { return compare_String(operation, (String) value1, value2); } + if (value1 instanceof Version) { + return compare_Version(operation, (Version) value1, value2); + } Class<?> clazz = value1.getClass(); if (clazz.isArray()) { @@ -1213,6 +1216,31 @@ public class FrameworkUtil { return false; } + private boolean compare_Version(int operation, Version value1, Object value2) { + if (operation == SUBSTRING) { + return false; + } + try { + Version version2 = Version.valueOf((String) value2); + switch (operation) { + case APPROX : + case EQUAL : { + return value1.compareTo(version2) == 0; + } + case GREATER : { + return value1.compareTo(version2) >= 0; + } + case LESS : { + return value1.compareTo(version2) <= 0; + } + } + } catch (Exception e) { + // if the valueOf or compareTo method throws an exception + return false; + } + return false; + } + private boolean compare_Unknown(int operation, Object value1, Object value2) { if (operation == SUBSTRING) { return false; |