Refactor: Put slicing of ArrayList into a separate method.
authorZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Wed, 28 Jan 2009 12:32:51 +0000 (12:32 +0000)
committerZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Wed, 28 Jan 2009 12:32:51 +0000 (12:32 +0000)
This should really be moved to ArrayList implementation.

svn path=/trunk/; revision=489

src/plugins/tracker/rygel-media-tracker.vala

index 08a900e..23b758c 100644 (file)
@@ -214,20 +214,32 @@ public class Rygel.MediaTracker : ContentDirectory {
         } else if (offset >= child_count) {
             throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
         } else {
-            // Make sure we don't go beyond the limits
-            max_count %= (child_count - offset);
+            children = slice_object_list (this.containers,
+                                          offset,
+                                          max_count);
+        }
 
-            if (max_count == 0) {
-                max_count = child_count - offset;
-            }
+        return children;
+    }
 
-            children = new ArrayList<MediaObject> ();
-            for (int i = 0; i < max_count; i++) {
-                children.add (this.containers.get (i + (int) offset));
-            }
+    private ArrayList<MediaObject> slice_object_list (
+                                        ArrayList<MediaObject> list,
+                                        uint                   offset,
+                                        uint                   max_count) {
+        uint total = list.size;
+
+        var slice = new ArrayList<MediaObject> ();
+
+        if (max_count == 0 || max_count > (total - offset)) {
+            max_count = total - offset;
         }
 
-        return children;
+        slice = new ArrayList<MediaObject> ();
+        for (uint i = offset; i < total; i++) {
+            slice.add (list[(int) i]);
+        }
+
+        return slice;
     }
 }