From commits-return-33650-archive-asf-public=cust-asf.ponee.io@karaf.apache.org Wed Apr 11 11:03:24 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 342FA18064A for ; Wed, 11 Apr 2018 11:03:24 +0200 (CEST) Received: (qmail 35921 invoked by uid 500); 11 Apr 2018 09:03:23 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 35911 invoked by uid 99); 11 Apr 2018 09:03:23 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Apr 2018 09:03:23 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 9044A850BF; Wed, 11 Apr 2018 09:03:22 +0000 (UTC) Date: Wed, 11 Apr 2018 09:03:22 +0000 To: "commits@karaf.apache.org" Subject: [karaf] branch master updated: Avoid intern() to reuse commons tring in SimpleFilter MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <152343740250.14581.11299873058494449109@gitbox.apache.org> From: flange@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: karaf X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: f434e39d9b632e1093b6790341c02ed263261d9f X-Git-Newrev: 2c45df88f166fa0892a71f30e347a0072e6f07f2 X-Git-Rev: 2c45df88f166fa0892a71f30e347a0072e6f07f2 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. flange pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/karaf.git The following commit(s) were added to refs/heads/master by this push: new 2c45df8 Avoid intern() to reuse commons tring in SimpleFilter 2c45df8 is described below commit 2c45df88f166fa0892a71f30e347a0072e6f07f2 Author: Fabian Lange AuthorDate: Wed Apr 11 11:01:46 2018 +0200 Avoid intern() to reuse commons tring in SimpleFilter --- .../features/internal/resolver/SimpleFilter.java | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/SimpleFilter.java b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/SimpleFilter.java index 02635d4..c33bda9 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/SimpleFilter.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/SimpleFilter.java @@ -19,12 +19,11 @@ package org.apache.karaf.features.internal.resolver; import java.util.ArrayList; import java.util.Collections; import java.util.Deque; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.felix.utils.version.VersionRange; @@ -43,15 +42,15 @@ public class SimpleFilter { /** * Strings which are commonly found in filter specification. We use this map as an interner. */ - private static final Set COMMON_STRINGS; + private static final ConcurrentHashMap COMMON_STRINGS; static { - Set s = new HashSet<>(8); - s.add("optional"); - s.add("osgi.ee"); - s.add("resolution"); - s.add("uses"); - s.add("version"); + ConcurrentHashMap s = new ConcurrentHashMap<>(8); + s.put("optional", "optional"); + s.put("osgi.ee", "osgi.ee"); + s.put("resolution", "resolution"); + s.put("uses", "uses"); + s.put("version", "version"); COMMON_STRINGS = s; } @@ -62,7 +61,7 @@ public class SimpleFilter { private final int op; SimpleFilter(String name, Object value, int op) { - this.name = internIfCommon(name); + this.name = reuseCommonString(name); this.value = value; this.op = op; } @@ -144,8 +143,14 @@ public class SimpleFilter { } } - private static String internIfCommon(String str) { - return str != null && COMMON_STRINGS.contains(str) ? str.intern() : str; + private static String reuseCommonString(String str) { + if (str != null) { + String commonString = COMMON_STRINGS.get(str); + if (commonString != null) { + return commonString; + } + } + return str; } private static void toString(StringBuilder sb, List list) { -- To stop receiving notification emails like this one, please contact flange@apache.org.