From b9b8c5c28d32e55e4d5848a306edfa0862f1955a Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Wed, 28 Jan 2009 12:32:51 +0000 Subject: [PATCH] Refactor: Put slicing of ArrayList into a separate method. This should really be moved to ArrayList implementation. svn path=/trunk/; revision=489 --- src/plugins/tracker/rygel-media-tracker.vala | 32 +++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/plugins/tracker/rygel-media-tracker.vala b/src/plugins/tracker/rygel-media-tracker.vala index 08a900e..23b758c 100644 --- a/src/plugins/tracker/rygel-media-tracker.vala +++ b/src/plugins/tracker/rygel-media-tracker.vala @@ -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 (); - for (int i = 0; i < max_count; i++) { - children.add (this.containers.get (i + (int) offset)); - } + private ArrayList slice_object_list ( + ArrayList list, + uint offset, + uint max_count) { + uint total = list.size; + + var slice = new ArrayList (); + + if (max_count == 0 || max_count > (total - offset)) { + max_count = total - offset; } - return children; + slice = new ArrayList (); + for (uint i = offset; i < total; i++) { + slice.add (list[(int) i]); + } + + return slice; } } -- 2.7.4