Explorar o código

refactor: extract va_list handling to Wrap module

Move the variadic argument processing logic from Iterate.these() to a new
Wrap.va_list() function for improved code reuse and organization.
Billy Barrow hai 1 semana
pai
achega
8edf68cd63
Modificáronse 2 ficheiros con 14 adicións e 11 borrados
  1. 1 11
      src/lib/Iterate.vala
  2. 13 0
      src/lib/Wrap.vala

+ 1 - 11
src/lib/Iterate.vala

@@ -24,17 +24,7 @@ namespace Invercargill.Iterate {
     }
 
     public static Enumerable<T> these<T>(owned T item1, ...) {
-        var vector = new Vector<T>();
-        var args = va_list();
-        vector.add(item1);
-        while(true) {
-            T? item = args.arg<T>();
-            if(item == null) {
-                break;
-            }
-            vector.add((owned)item);
-        }
-        return vector.to_buffer().seal();
+        return Wrap.va_list<T>(item1, va_list());
     }
 
     public static Enumerable<T> deferred<T>(owned Generators.DeferredDelegate<T> function) {

+ 13 - 0
src/lib/Wrap.vala

@@ -5,6 +5,19 @@ namespace Invercargill.Wrap {
         return new Wrappers.Array<T>(input);
     }
 
+    public static ReadOnlyAddressable<T> @va_list<T>(T initial, va_list list) {
+        var vector = new Vector<T>();
+        vector.add(initial);
+        while(true) {
+            T? item = list.arg<T>();
+            if(item == null) {
+                break;
+            }
+            vector.add((owned)item);
+        }
+        return vector.to_immutable_buffer();
+    }
+
     public static Lot<T> generic_array<T>(owned GLib.GenericArray<T> input) {
         return new Wrappers.GenericArray<T>((owned)input);
     }