You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by GitBox <gi...@apache.org> on 2018/07/16 16:49:26 UTC

[GitHub] pnicolucci closed pull request #12: MYFACES-4247: reduce number of char[] objects and CommonPropertyUtils…

pnicolucci closed pull request #12: MYFACES-4247: reduce number of char[] objects and CommonPropertyUtils…
URL: https://github.com/apache/myfaces/pull/12
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java
index da0c3882c..110ff4225 100755
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlLabelRenderer.java
@@ -140,7 +140,7 @@ public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) thro
             if (isCommonPropertiesOptimizationEnabled(facesContext))
             {
                 CommonPropertyUtils.renderLabelPassthroughPropertiesWithoutEvents(writer, 
-                        CommonPropertyUtils.getCommonPropertiesMarked(uiComponent), uiComponent);
+                        commonPropertiesMarked, uiComponent);
             }
             else
             {
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/util/FastWriter.java b/impl/src/main/java/org/apache/myfaces/view/facelets/util/FastWriter.java
index ba00f97c0..c34abdb9d 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/util/FastWriter.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/util/FastWriter.java
@@ -86,12 +86,14 @@ public void write(int c) throws IOException
 
     public void write(String str, int off, int len) throws IOException
     {
-        this.write(str.toCharArray(), off, len);
+        overflow(len);
+        str.getChars(off, off+len, this.buff, size);
+        this.size += len;
     }
 
     public void write(String str) throws IOException
     {
-        this.write(str.toCharArray(), 0, str.length());
+        this.write(str, 0, str.length());
     }
 
     public void reset()
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/util/FastWriterTest.java b/impl/src/test/java/org/apache/myfaces/view/facelets/util/FastWriterTest.java
new file mode 100644
index 000000000..465b0c589
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/util/FastWriterTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.myfaces.view.facelets.util;
+
+import org.apache.myfaces.view.facelets.util.FastWriter;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class FastWriterTest 
+{
+    // Test FastWriter.write(String str, int off, int len)
+    @Test
+    public void testFastWriterWriteString() throws Exception
+    {
+        String sampleStringToWrite = "Test String to write";
+        
+        FastWriter fw = new FastWriter();
+        fw.write(sampleStringToWrite, 0, sampleStringToWrite.length());
+
+        // fw.toString() should be: Test String to write
+        Assert.assertEquals(fw.toString(), sampleStringToWrite);
+    }
+    
+    @Test
+    public void testFastWriterWriteStringOffSet() throws Exception
+    {
+        int offSet = 5;
+        String sampleStringToWrite = "Test String to write";
+        
+        FastWriter fw = new FastWriter();
+        fw.write(sampleStringToWrite, offSet, sampleStringToWrite.length() - offSet);
+
+        // fw.toString() should be: String to write
+        Assert.assertEquals(fw.toString(), sampleStringToWrite.substring(offSet));
+    }
+    
+    @Test
+    public void testFastWriterWriteStringLength() throws Exception
+    {
+       String sampleStringToWrite = "Test String to write";
+       int length = sampleStringToWrite.substring(0, sampleStringToWrite.indexOf(" ")).length();
+       
+       FastWriter fw = new FastWriter();
+       fw.write(sampleStringToWrite, 0, length);
+
+       // fw.toString() should be: Test
+       Assert.assertEquals(fw.toString(), sampleStringToWrite.substring(0,length));
+    }
+}
\ No newline at end of file
diff --git a/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlGroupRendererBase.java b/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlGroupRendererBase.java
index c7acbd59d..85fe387d7 100644
--- a/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlGroupRendererBase.java
+++ b/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlGroupRendererBase.java
@@ -99,7 +99,7 @@ public void encodeEnd(FacesContext context, UIComponent component)
             {
                 commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(component);
                 CommonPropertyUtils.renderCommonPassthroughPropertiesWithoutEvents(writer, 
-                        CommonPropertyUtils.getCommonPropertiesMarked(component), component);
+                        commonPropertiesMarked, component);
             }
             else
             {
diff --git a/shared/src/main/java/org/apache/myfaces/shared/util/FastWriter.java b/shared/src/main/java/org/apache/myfaces/shared/util/FastWriter.java
index 6897f3f73..5bee179f0 100644
--- a/shared/src/main/java/org/apache/myfaces/shared/util/FastWriter.java
+++ b/shared/src/main/java/org/apache/myfaces/shared/util/FastWriter.java
@@ -89,12 +89,14 @@ public void write(int c) throws IOException
 
     public void write(String str, int off, int len) throws IOException
     {
-        this.write(str.toCharArray(), off, len);
+        overflow(len);
+        str.getChars(off, off+len, this.buff, size);
+        this.size += len;
     }
 
     public void write(String str) throws IOException
     {
-        this.write(str.toCharArray(), 0, str.length());
+        this.write(str, 0, str.length());
     }
 
     public void reset()


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services