[pulseaudio-commits] r1536 - /branches/lennart/src/pulsecore/strlist.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Jul 25 14:28:57 PDT 2007


Author: lennart
Date: Wed Jul 25 23:28:56 2007
New Revision: 1536

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1536&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Store strings directly in strlst elements, other modernizations

Modified:
    branches/lennart/src/pulsecore/strlist.c

Modified: branches/lennart/src/pulsecore/strlist.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
strlist.c?rev=3D1536&root=3Dpulseaudio&r1=3D1535&r2=3D1536&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/strlist.c (original)
+++ branches/lennart/src/pulsecore/strlist.c Wed Jul 25 23:28:56 2007
@@ -26,26 +26,31 @@
 #endif
 =

 #include <string.h>
-#include <assert.h>
 =

 #include <pulse/xmalloc.h>
 =

 #include <pulsecore/strbuf.h>
+#include <pulsecore/macro.h>
 #include <pulsecore/core-util.h>
 =

 #include "strlist.h"
 =

 struct pa_strlist {
     pa_strlist *next;
-    char *str;
 };
+
+#define ITEM_TO_TEXT(c) ((char*) (c) + PA_ALIGN(sizeof(pa_strlist)))
 =

 pa_strlist* pa_strlist_prepend(pa_strlist *l, const char *s) {
     pa_strlist *n;
-    assert(s);
-    n =3D pa_xmalloc(sizeof(pa_strlist));
-    n->str =3D pa_xstrdup(s);
+    size_t size;
+    =

+    pa_assert(s);
+    size =3D strlen(s);
+    n =3D pa_xmalloc(PA_ALIGN(sizeof(pa_strlist)) + size + 1);
+    memcpy(ITEM_TO_TEXT(n), s, size + 1);
     n->next =3D l;
+
     return  n;
 }
 =

@@ -58,7 +63,7 @@
         if (!first)
             pa_strbuf_puts(b, " ");
         first =3D 0;
-        pa_strbuf_puts(b, l->str);
+        pa_strbuf_puts(b, ITEM_TO_TEXT(l));
     }
 =

     return pa_strbuf_tostring_free(b);
@@ -66,19 +71,20 @@
 =

 pa_strlist* pa_strlist_remove(pa_strlist *l, const char *s) {
     pa_strlist *ret =3D l, *prev =3D NULL;
-    assert(l && s);
+
+    pa_assert(l);
+    pa_assert(s);
 =

     while (l) {
-        if (!strcmp(l->str, s)) {
+        if (!strcmp(ITEM_TO_TEXT(l), s)) {
             pa_strlist *n =3D l->next;
 =

             if (!prev) {
-                assert(ret =3D=3D l);
+                pa_assert(ret =3D=3D l);
                 ret =3D n;
             } else
                 prev->next =3D n;
 =

-            pa_xfree(l->str);
             pa_xfree(l);
 =

             l =3D n;
@@ -96,22 +102,21 @@
     while (l) {
         pa_strlist *c =3D l;
         l =3D l->next;
-
-        pa_xfree(c->str);
         pa_xfree(c);
     }
 }
 =

 pa_strlist* pa_strlist_pop(pa_strlist *l, char **s) {
     pa_strlist *r;
-    assert(s);
+    =

+    pa_assert(s);
 =

     if (!l) {
         *s =3D NULL;
         return NULL;
     }
 =

-    *s =3D l->str;
+    *s =3D pa_xstrdup(ITEM_TO_TEXT(l));
     r =3D l->next;
     pa_xfree(l);
     return r;
@@ -124,10 +129,12 @@
 =

     while ((r =3D pa_split_spaces(s, &state))) {
         pa_strlist *n;
+        size_t size =3D strlen(r);
 =

-        n =3D pa_xmalloc(sizeof(pa_strlist));
-        n->str =3D r;
+        n =3D pa_xmalloc(PA_ALIGN(sizeof(pa_strlist)) + size + 1);
         n->next =3D NULL;
+        memcpy(ITEM_TO_TEXT(n), r, size+1);
+        pa_xfree(r);
 =

         if (p)
             p->next =3D n;




More information about the pulseaudio-commits mailing list