You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/08/06 21:55:15 UTC

[groovy] branch master updated: minor refactoring: avoid div by zero for empty GString strings

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 22aaa6c  minor refactoring: avoid div by zero for empty GString strings
22aaa6c is described below

commit 22aaa6cc41dd373bde65f8cb6de9fcc928e8cebf
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Aug 7 07:55:04 2020 +1000

    minor refactoring: avoid div by zero for empty GString strings
---
 src/main/java/org/codehaus/groovy/runtime/GStringUtil.java | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/GStringUtil.java b/src/main/java/org/codehaus/groovy/runtime/GStringUtil.java
index c89053a..a9a80a2 100644
--- a/src/main/java/org/codehaus/groovy/runtime/GStringUtil.java
+++ b/src/main/java/org/codehaus/groovy/runtime/GStringUtil.java
@@ -119,7 +119,9 @@ public final class GStringUtil {
         for (String string : ss) {
             initialCapacity += string.length();
         }
-        initialCapacity += vs.length * Math.max(initialCapacity / ss.length, 8);
+        if (ss.length != 0) {
+            initialCapacity += vs.length * Math.max(initialCapacity / ss.length, 8);
+        }
         return Math.max((int) (initialCapacity * 1.2), 16);
     }
 }