Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r1594 - trunk: . fsvs/src

fsvs
Discussion topic

Back to topic list

svn commit: r1594 - trunk: . fsvs/src

Author pmarek
Full name P.Marek
Date 2008-04-08 23:45:42 PDT
Message Author: pmarek
Date: 2008-04-08 23:45:42-0700
New Revision: 1594

Modified:
   trunk/ (props changed)
   trunk/fsvs/src/status.c

Log:
Changed st___string_from_bits() to use a cache for the output.


Modified: trunk/fsvs/src/status.c
Url: http://fsvs.tigris.o​rg/source/browse/fsv​s/trunk/fsvs/src/sta​tus.c?view=diff&​rev=1594&p1=trun​k/fsvs/src/status.c​&p2=trunk/fsvs/sr​c/status.c&r1=15​93&r2=1594
====================​====================​====================​==================
--- trunk/fsvs/src/status.c (original)
+++ trunk/fsvs/src/status.c 2008-04-08 23:45:42-0700
@@ -518,18 +518,26 @@
 #define BIT_INFO(v, s) { .val=v, .string=s, .str_len=strlen(s) }
 
 
-/** Constructs a string from a bitmask, where one or more bits may be set. */
+/** Constructs a string from a bitmask, where one or more bits may be set.
+ *
+ * Must not be free()d. */
 #define st___string_from_bits(v, a, t) _st___string_from_bits(v, a, sizeof(a)/sizeof(a[0]), t)
 volatile char *_st___string_from_bits(int value,
         const struct st___bit_info data[], int max,
         char *text_for_none)
 {
+ int status;
+ static struct cache_t *cache=NULL;
     static const char sep[]=", ";
- static char *string=NULL;
- static int len=0;
+ char *string;
     int i;
     int last_len, new_len;
+ struct cache_entry_t **cc;
+
 
+ STOPIF( cch__new_cache(&cache, 4), NULL);
+ STOPIF( cch__add(cache, 0, NULL, 128, &string), NULL);
+ cc=cache->entries + cache->lru;
 
     last_len=0;
     if (string) *string=0;
@@ -540,13 +548,9 @@
             new_len = last_len + data[i].str_len +
                 (last_len ? strlen(sep) : 0);
 
- while (new_len + 8 > len)
+ if (new_len + 8 > (*cc)->len)
             {
- if (!len) len=256;
- len *= 2;
- string=realloc(string, len);
- /* Cannot use STOPIF_ENOMEM() - we want to return a char* */
- if (!string) return NULL;
+ STOPIF( cch__entry_set(cc, 0, NULL, new_len+64, 1, &string), NULL);
                 string[last_len]=0;
             }
 
@@ -567,6 +571,9 @@
         }
     }
 
+ex:
+ /* Is that good? */
+ if (status) return NULL;
     /* If no bits are set, return "empty" */
     return string && *string ? string : text_for_none;
 }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r1594 - trunk: . fsvs/src pmarek P.Marek 2008-04-08 23:45:42 PDT
Messages per page: