harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Ellison (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (HARMONY-6323) [classlib] [luni] Simplify and speed-up collection shuffle, add a non-probabilistic test
Date Fri, 04 Sep 2009 12:34:57 GMT

     [ https://issues.apache.org/jira/browse/HARMONY-6323?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Tim Ellison resolved HARMONY-6323.
----------------------------------

    Resolution: Fixed

Jesse, the fix required changing the impl to work the same way as before, swapping all the
way down to the second element.

Index: src/main/java/java/util/Collections.java
===================================================================
--- src/main/java/java/util/Collections.java	(revision 811363)
+++ src/main/java/java/util/Collections.java	(working copy)
@@ -1844,13 +1844,13 @@
         final List<Object> objectList = (List<Object>) list;
 
         if (list instanceof RandomAccess) {
-            for (int i = objectList.size() - 1; i > 1; i--) {
+            for (int i = objectList.size() - 1; i > 0; i--) {
                 int index = random.nextInt(i + 1);
                 objectList.set(index, objectList.set(i, objectList.get(index)));
             }
         } else {
             Object[] array = objectList.toArray();
-            for (int i = array.length - 1; i > 1; i--) {
+            for (int i = array.length - 1; i > 0; i--) {
                 int index = random.nextInt(i + 1);
                 Object temp = array[i];
                 array[i] = array[index];

The fix and tests were committed to the LUNI module at repo revision r811363.

Please check you agree with this fix.


> [classlib] [luni] Simplify and speed-up collection shuffle, add a non-probabilistic test
> ----------------------------------------------------------------------------------------
>
>                 Key: HARMONY-6323
>                 URL: https://issues.apache.org/jira/browse/HARMONY-6323
>             Project: Harmony
>          Issue Type: Improvement
>          Components: Classlib
>         Environment: SVN Revision 801399
>            Reporter: Jesse Wilson
>            Assignee: Tim Ellison
>            Priority: Minor
>             Fix For: 5.0M12
>
>         Attachments: Shuffle-fixes.patch
>
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> Shuffle needlessly tests Random.nextInt() for a negative value
> It iterates from index N-1 to 0, which means it always swaps index 0 with itself needlessly.
> It is only tested with probabilistic tests, the patch adds a proper test. Note that the
attached test also passes on the RI.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message