deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject git commit: DELTASPIKE-506 [perf] use a shared StringBuilder
Date Thu, 31 Jul 2014 21:09:11 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master da28876d3 -> 2be8af863


DELTASPIKE-506 [perf] use a shared StringBuilder

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/2be8af86
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/2be8af86
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/2be8af86

Branch: refs/heads/master
Commit: 2be8af863f2dbfe3685d2fb139c985a08f3d926e
Parents: da28876
Author: tandraschko <tandraschko@apache.org>
Authored: Thu Jul 31 23:08:55 2014 +0200
Committer: tandraschko <tandraschko@apache.org>
Committed: Thu Jul 31 23:08:55 2014 +0200

----------------------------------------------------------------------
 .../jsf/impl/util/ClientWindowHelper.java       |  2 -
 .../deltaspike/jsf/impl/util/JsfUtils.java      |  5 +-
 .../jsf/impl/util/SharedStringBuilder.java      | 61 ++++++++++++++++++++
 3 files changed, 65 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2be8af86/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
index 40b948b..f8faaab 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/ClientWindowHelper.java
@@ -98,8 +98,6 @@ public abstract class ClientWindowHelper
 
                 for (Entry<String, String> entry : parameters.entrySet())
                 {
-                    // NOTE: each call will instantiate a new StringBuilder
-                    // i didn't optimized this call because it's unlikely that there will
be multiple parameters
                     targetUrl = JsfUtils.addParameter(facesContext.getExternalContext(),
                             targetUrl,
                             true,

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2be8af86/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
index d360409..fd1afaa 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/JsfUtils.java
@@ -40,6 +40,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
 
 public abstract class JsfUtils
 {
+    private static final String SB_ADD_PARAMETER = "SB:" + JsfUtils.class + "#addParameter";
+    
     public static <T> T getValueOfExpression(String expression, Class<T> targetType)
     {
         FacesContext facesContext = FacesContext.getCurrentInstance();
@@ -145,7 +147,8 @@ public abstract class JsfUtils
             return url;
         }
 
-        StringBuilder finalUrl = new StringBuilder(url);
+        StringBuilder finalUrl = SharedStringBuilder.get(SB_ADD_PARAMETER);
+        finalUrl.append(url);
 
         if (url.contains("?"))
         {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2be8af86/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/SharedStringBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/SharedStringBuilder.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/SharedStringBuilder.java
new file mode 100644
index 0000000..6b0fb57
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/util/SharedStringBuilder.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.jsf.impl.util;
+
+import javax.enterprise.inject.Typed;
+import javax.faces.context.FacesContext;
+
+@Typed()
+public abstract class SharedStringBuilder
+{
+    /**
+     * Get a shared {@link StringBuilder} instance.
+     *
+     * @param context The {@link FacesContext}
+     * @param key The unique key per use case.
+     * @return The shared {@link StringBuilder} instance
+     */
+    public static StringBuilder get(FacesContext context, String key)
+    {
+        StringBuilder builder = (StringBuilder) context.getAttributes().get(key);
+
+        if (builder == null)
+        {
+            builder = new StringBuilder();
+            context.getAttributes().put(key, builder);
+        }
+        else
+        {
+            builder.setLength(0);
+        }
+
+        return builder;
+    }
+
+    /**
+     * Get a shared {@link StringBuilder} instance.
+     *
+     * @param key The unique key per use case.
+     * @return The shared {@link StringBuilder} instance
+     */
+    public static StringBuilder get(String key)
+    {
+        return get(FacesContext.getCurrentInstance(), key);
+    }
+}


Mime
View raw message