[geary/wip/734757-msgset] Make sparse MessageSet builders return list, not one, MessageSet



commit dfb143b3410ab243add6e7e5bc04b74199254eb3
Author: Jim Nelson <jim yorba org>
Date:   Wed Aug 13 19:32:20 2014 -0700

    Make sparse MessageSet builders return list, not one, MessageSet

 src/engine/imap/command/imap-message-set.vala |   59 ++++++++++---------------
 1 files changed, 23 insertions(+), 36 deletions(-)
---
diff --git a/src/engine/imap/command/imap-message-set.vala b/src/engine/imap/command/imap-message-set.vala
index 9dc7f38..b410e39 100644
--- a/src/engine/imap/command/imap-message-set.vala
+++ b/src/engine/imap/command/imap-message-set.vala
@@ -95,54 +95,41 @@ public class Geary.Imap.MessageSet : BaseObject {
         is_uid = true;
     }
     
-    public MessageSet.sparse(SequenceNumber[] seq_nums) {
-        value = build_sparse_range(seq_array_to_int64(seq_nums));
+    public static Gee.List<MessageSet> sparse(SequenceNumber[] seq_nums) {
+        return build_sparse(seq_array_to_int64(seq_nums), false);
     }
     
-    public MessageSet.uid_sparse(UID[] msg_uids) {
-        value = build_sparse_range(uid_array_to_int64(msg_uids));
-        is_uid = true;
+    public static Gee.List<MessageSet> uid_sparse(UID[] msg_uids) {
+        return build_sparse(uid_array_to_int64(msg_uids), true);
     }
     
-    public MessageSet.sparse_to_highest(SequenceNumber[] seq_nums) {
-        value = "%s:*".printf(build_sparse_range(seq_array_to_int64(seq_nums)));
-    }
+    private const int MAX_SPARSE_VALUES = 5;
     
-    public MessageSet.multirange(MessageSet[] msg_sets) {
-        StringBuilder builder = new StringBuilder();
-        for (int ctr = 0; ctr < msg_sets.length; ctr++) {
-            unowned MessageSet msg_set = msg_sets[ctr];
-            
-            if (ctr < (msg_sets.length - 1))
-                builder.append_printf("%s:", msg_set.value);
-            else
-                builder.append(msg_set.value);
-        }
+    private static Gee.List<MessageSet> build_sparse(int64[] sorted, bool is_uid) {
+        Gee.List<MessageSet> list = new Gee.ArrayList<MessageSet>();
         
-        value = builder.str;
-    }
-    
-    public MessageSet.multisparse(MessageSet[] msg_sets) {
-        StringBuilder builder = new StringBuilder();
-        for (int ctr = 0; ctr < msg_sets.length; ctr++) {
-            unowned MessageSet msg_set = msg_sets[ctr];
+        int start_index = 0;
+        for (;;) {
+            if (start_index >= sorted.length)
+                break;
             
-            if (ctr < (msg_sets.length - 1))
-                builder.append_printf("%s,", msg_set.value);
-            else
-                builder.append(msg_set.value);
+            int end_index = (start_index + MAX_SPARSE_VALUES).clamp(0, sorted.length - 1);
+            int64[] slice = sorted[start_index:end_index];
+            
+            debug("MessageSet.build_sparse: sorted=%d start_index=%d end_index=%d slice=%d",
+                sorted.length, start_index, end_index, slice.length);
+            
+            list.add(new MessageSet.custom(build_sparse_range(slice), is_uid));
+            
+            start_index += MAX_SPARSE_VALUES;
         }
         
-        value = builder.str;
+        return list;
     }
     
-    public MessageSet.custom(string custom) {
+    private MessageSet.custom(string custom, bool is_uid) {
         value = custom;
-    }
-    
-    public MessageSet.uid_custom(string custom) {
-        value = custom;
-        is_uid = true;
+        this.is_uid = is_uid;
     }
     
     // Builds sparse range of either UID values or message numbers.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]