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 2021/01/15 05:00:50 UTC

[groovy] branch GROOVY_2_5_X updated (c31af6f -> 94a2167)

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

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


    from c31af6f  Remove NSIS stuff since Windows installer no longer uses that
     new 85ac873  last() method for LinkedList can be more efficient (closes #1456)
     new 94a2167  last() method for LinkedList can be more efficient (tweaks)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/codehaus/groovy/runtime/DefaultGroovyMethods.java   | 13 +++++++++++++
 1 file changed, 13 insertions(+)


[groovy] 02/02: last() method for LinkedList can be more efficient (tweaks)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 94a2167f2593a405f4348d30d9da90abfb88683c
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Jan 15 14:58:19 2021 +1000

    last() method for LinkedList can be more efficient (tweaks)
---
 .../groovy/runtime/DefaultGroovyMethods.java       | 23 ++++++----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 6a6c7f9..1ef642e 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -143,6 +143,7 @@ import java.util.BitSet;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Deque;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -9773,25 +9774,14 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         return true;
     }
 
-
-     /**
-     * Returns the last item from the LinkedList.
-     * <pre class="groovyTestCase">
-     * def list = [3, 4, 2]
-     * assert list.last() == 2
-     * // check original is unaltered
-     * assert list == [3, 4, 2]
-     * </pre>
+    /**
+     * An optimized version of {@link #last(List)}.
      *
-     * @param self a List
-     * @return the last item from the List
-     * @throws NoSuchElementException if the list is empty and you try to access the last() item.
-     * @since 1.5.5
+     * @since 2.5.15
      */
-    public static <T> T last(LinkedList<T> self) {
-
+    public static <T> T last(Deque<T> self) {
         if (self.isEmpty()) {
-            throw new NoSuchElementException("Cannot access last() element from an empty List");
+            throw new NoSuchElementException("Cannot access last() element from an empty Deque");
         }
         return self.getLast();
     }
@@ -9811,7 +9801,6 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.5
      */
     public static <T> T last(List<T> self) {
-
         if (self.isEmpty()) {
             throw new NoSuchElementException("Cannot access last() element from an empty List");
         }


[groovy] 01/02: last() method for LinkedList can be more efficient (closes #1456)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 85ac8738a563c145a510e63cc9d498e8fea08f98
Author: davydotcom <da...@gmail.com>
AuthorDate: Thu Jan 14 10:29:12 2021 -0500

    last() method for LinkedList can be more efficient (closes #1456)
---
 .../groovy/runtime/DefaultGroovyMethods.java       | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 89e6278..6a6c7f9 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -9773,6 +9773,29 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         return true;
     }
 
+
+     /**
+     * Returns the last item from the LinkedList.
+     * <pre class="groovyTestCase">
+     * def list = [3, 4, 2]
+     * assert list.last() == 2
+     * // check original is unaltered
+     * assert list == [3, 4, 2]
+     * </pre>
+     *
+     * @param self a List
+     * @return the last item from the List
+     * @throws NoSuchElementException if the list is empty and you try to access the last() item.
+     * @since 1.5.5
+     */
+    public static <T> T last(LinkedList<T> self) {
+
+        if (self.isEmpty()) {
+            throw new NoSuchElementException("Cannot access last() element from an empty List");
+        }
+        return self.getLast();
+    }
+
     /**
      * Returns the last item from the List.
      * <pre class="groovyTestCase">
@@ -9788,6 +9811,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.5
      */
     public static <T> T last(List<T> self) {
+
         if (self.isEmpty()) {
             throw new NoSuchElementException("Cannot access last() element from an empty List");
         }