]> mj.ucw.cz Git - libucw.git/commitdiff
Fastbuf: fbmulti: O(N^2) multiappend fixed
authorJan 'Moskyt' Matejka <mq@ucw.cz>
Thu, 19 Jul 2012 07:59:52 +0000 (09:59 +0200)
committerJan 'Moskyt' Matejka <mq@ucw.cz>
Thu, 19 Jul 2012 13:25:29 +0000 (15:25 +0200)
ucw/fb-multi.c

index 715705c6fdbc06afacea36773bece4f42591ad95..9acf8b0f5ab596d3c89f496266f6686b72e0e5c9 100644 (file)
@@ -183,23 +183,6 @@ fbmulti_seek(struct fastbuf *f, ucw_off_t pos, int whence)
     }
 }
 
-static void
-fbmulti_update_capability(struct fastbuf *f)
-{
-  // FB Multi is only a proxy to other fastbufs ... if any of them lacks
-  // support of any feature, FB Multi also provides no support of that feature
-  f->refill = fbmulti_refill;
-  f->seek = fbmulti_seek;
-
-  CLIST_FOR_EACH(struct subbuf *, n, *(FB_MULTI(f)->subbufs))
-    {
-      ASSERT(n->fb->refill);
-
-      if (!n->fb->seek)
-       f->seek = NULL;
-    }
-}
-
 static void
 fbmulti_close(struct fastbuf *f)
 {
@@ -242,6 +225,8 @@ fbmulti_create(uns bufsize, ...)
     }
 
   fb_out->name = FB_MULTI_NAME;
+  f->refill = fbmulti_refill;
+  f->seek = fbmulti_seek;
 
   fb_out->close = fbmulti_close;
 
@@ -251,6 +236,10 @@ fbmulti_create(uns bufsize, ...)
 void
 fbmulti_append(struct fastbuf *f, struct fastbuf *fb)
 {
+  ASSERT(fb->refill);
+  if (!fb->seek)
+    f->seek = NULL;
+
   struct subbuf *sb = mp_alloc(FB_MULTI(f)->mp, sizeof(struct subbuf));
   sb->fb = fb;
   clist_add_tail(FB_MULTI(f)->subbufs, &(sb->n));