diff options
author | Thomas Watson | 2017-01-17 14:25:25 +0000 |
---|---|---|
committer | Thomas Watson | 2017-01-17 14:25:25 +0000 |
commit | fdda10401d86fb1589acb072b5c52bb46ee0804c (patch) | |
tree | 4f3b32ef715c040e7c3669f7a9ce349e4bab5b8d | |
parent | baa04768e2b5e885a64ee9cd75fa63599ff74f14 (diff) | |
download | rt.equinox.bundles-fdda10401d86fb1589acb072b5c52bb46ee0804c.tar.gz rt.equinox.bundles-fdda10401d86fb1589acb072b5c52bb46ee0804c.tar.xz rt.equinox.bundles-fdda10401d86fb1589acb072b5c52bb46ee0804c.zip |
Bug 510583 - [region] optimize the ALL filter
Change-Id: Ib0c546f4449b6db05a1aa27749aec43c8bb69a57
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
2 files changed, 23 insertions, 19 deletions
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilter.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilter.java index ab8a61866..46c786515 100644 --- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilter.java +++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilter.java @@ -19,6 +19,18 @@ import org.osgi.framework.wiring.BundleCapability; import org.osgi.framework.wiring.BundleRevision; public final class StandardRegionFilter implements RegionFilter { + final static Filter ALL; + + static { + try { + ALL = FrameworkUtil.createFilter("(|(!(all=*))(all=*))"); //$NON-NLS-1$ + } catch (InvalidSyntaxException e) { + // should never happen! + e.printStackTrace(); + throw new RuntimeException(e); + } + } + private static final String BUNDLE_ID_ATTR = "id"; //$NON-NLS-1$ private final Map<String, Collection<Filter>> filters; @@ -75,7 +87,7 @@ public final class StandardRegionFilter implements RegionFilter { if (filters == null) return false; for (Filter filter : filters) { - if (filter.matches(attrs)) + if (filter == ALL || filter.matches(attrs)) return true; } return false; @@ -85,7 +97,7 @@ public final class StandardRegionFilter implements RegionFilter { if (filters == null) return false; for (Filter filter : filters) { - if (filter.match(service)) + if (filter == ALL || filter.match(service)) return true; } return false; diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilterBuilder.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilterBuilder.java index d0315406e..b61ab0806 100644 --- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilterBuilder.java +++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionFilterBuilder.java @@ -21,20 +21,6 @@ import org.osgi.framework.*; public final class StandardRegionFilterBuilder implements RegionFilterBuilder { - private final static String ALL_SPEC = "(|(!(all=*))(all=*))"; //$NON-NLS-1$ - - private final static Filter ALL; - - static { - try { - ALL = FrameworkUtil.createFilter(ALL_SPEC); - } catch (InvalidSyntaxException e) { - // should never happen! - e.printStackTrace(); - throw new RuntimeException(e); - } - } - private final Object monitor = new Object(); private final Map<String, Collection<Filter>> policy = new HashMap<String, Collection<Filter>>(); @@ -52,8 +38,8 @@ public final class StandardRegionFilterBuilder implements RegionFilterBuilder { namespaceFilters = new LinkedHashSet<Filter>(); policy.put(namespace, namespaceFilters); } - // TODO need to use BundleContext.createFilter here - namespaceFilters.add(FrameworkUtil.createFilter(filter)); + + namespaceFilters.add(createFilter(filter)); } if (VISIBLE_SERVICE_NAMESPACE.equals(namespace)) { // alias the deprecated namespace to osgi.service @@ -62,6 +48,12 @@ public final class StandardRegionFilterBuilder implements RegionFilterBuilder { return this; } + public Filter createFilter(String spec) throws InvalidSyntaxException { + // TODO need to use BundleContext.createFilter here + Filter filter = FrameworkUtil.createFilter(spec); + return (StandardRegionFilter.ALL.equals(filter)) ? StandardRegionFilter.ALL : filter; + } + @SuppressWarnings("deprecation") public RegionFilterBuilder allowAll(String namespace) { if (namespace == null) @@ -75,7 +67,7 @@ public final class StandardRegionFilterBuilder implements RegionFilterBuilder { } // remove any other filters since this will override them all. namespaceFilters.clear(); - namespaceFilters.add(ALL); + namespaceFilters.add(StandardRegionFilter.ALL); } if (VISIBLE_SERVICE_NAMESPACE.equals(namespace)) { // alias the deprecated namespace to osgi.service |