summaryrefslogtreecommitdiff
path: root/src/fcfs.c
diff options
context:
space:
mode:
authorPatrick Lam <plam@MIT.EDU>2005-08-24 06:21:30 +0000
committerPatrick Lam <plam@MIT.EDU>2005-08-24 06:21:30 +0000
commit4262e0b3853bc2153270eb33d09a063f852f3f90 (patch)
treeba08c194f10446f4318c72538f9df5e812f1e462 /src/fcfs.c
parent212c9f437e959fbdc5fe344c67b8c1cf8ca63edb (diff)
downloadfontconfig-4262e0b3853bc2153270eb33d09a063f852f3f90.tar.gz
Overhaul the serialization system to create one mmapable file per directory
and distribute bytes for each directory from a single malloc for that directory. Store pointers as differences between the data pointed to and the pointer's address (s_off = s - v). Don't serialize data structures that never actually get serialized. Separate strings used for keys from strings used for values (in FcPatternElt and FcValue, respectively). Bump FC_CACHE_VERSION to 2.
Diffstat (limited to 'src/fcfs.c')
-rw-r--r--src/fcfs.c154
1 files changed, 58 insertions, 96 deletions
diff --git a/src/fcfs.c b/src/fcfs.c
index f362e2b..1e5aa81 100644
--- a/src/fcfs.c
+++ b/src/fcfs.c
@@ -81,27 +81,58 @@ FcFontSetAdd (FcFontSet *s, FcPattern *font)
return FcTrue;
}
-FcBool
-FcFontSetPrepareSerialize (FcFontSet *s)
+static int * fcfs_pat_count;
+
+void
+FcFontSetNewBank (void)
{
- int i;
+ FcPatternNewBank();
+ FcObjectNewBank();
+}
+
+int
+FcFontSetNeededBytes (FcFontSet *s)
+{
+ int i, c, cum = 0;
for (i = 0; i < s->nfont; i++)
- if (!FcPatternPrepareSerialize(s->fonts[i]))
- return FcFalse;
+ {
+ c = FcPatternNeededBytes(s->fonts[i]);
+ if (c < 0)
+ return c;
+ cum += c;
+ }
- return FcTrue;
+ if (cum > 0)
+ return cum + sizeof(int);
+ else
+ return 0;
+}
+
+void *
+FcFontSetDistributeBytes (FcCache * metadata, void * block_ptr)
+{
+ fcfs_pat_count = (int *)block_ptr;
+ block_ptr = (int *)block_ptr + 1;
+ // we don't consume any bytes for the fontset itself,
+ // since we don't allocate it statically.
+ block_ptr = FcPatternDistributeBytes (metadata, block_ptr);
+
+ // for good measure, write out the object ids used for
+ // this bank to the file.
+ return FcObjectDistributeBytes (metadata, block_ptr);
}
FcBool
-FcFontSetSerialize (FcFontSet * s)
+FcFontSetSerialize (int bank, FcFontSet * s)
{
int i;
FcPattern * p;
+ *fcfs_pat_count = s->nfont;
for (i = 0; i < s->nfont; i++)
{
- p = FcPatternSerialize (s->fonts[i]);
+ p = FcPatternSerialize (bank, s->fonts[i]);
if (!p) return FcFalse;
FcPatternDestroy (s->fonts[i]);
@@ -111,103 +142,34 @@ FcFontSetSerialize (FcFontSet * s)
return FcTrue;
}
-void
-FcFontSetClearStatic (void)
-{
- FcPatternClearStatic();
-}
-
FcBool
-FcFontSetRead(int fd, FcConfig * config, FcCache metadata)
+FcFontSetUnserialize(FcCache metadata, FcFontSet * s, void * block_ptr)
{
- int i, mz, j;
- FcPattern * buf;
+ int nfont;
+ int i, n;
- lseek(fd, metadata.fontsets_offset, SEEK_SET);
- for (i = FcSetSystem; i <= FcSetApplication; i++)
- {
- if (config->fonts[i])
- {
- if (config->fonts[i]->nfont > 0 && config->fonts[i]->fonts)
- free (config->fonts[i]->fonts);
- free (config->fonts[i]);
- }
- }
+ nfont = *(int *)block_ptr;
+ block_ptr = (int *)block_ptr + 1;
- for (i = FcSetSystem; i <= FcSetApplication; i++)
+ if (s->sfont < s->nfont + nfont)
{
- read(fd, &mz, sizeof(int));
- if (mz != FC_CACHE_MAGIC)
- continue;
-
- config->fonts[i] = malloc(sizeof(FcFontSet));
- if (!config->fonts[i])
- return FcFalse;
- FcMemAlloc(FC_MEM_FONTSET, sizeof(FcFontSet));
-
- if (read(fd, config->fonts[i], sizeof(FcFontSet)) == -1)
- goto bail;
- if (config->fonts[i]->sfont > 0)
- {
- config->fonts[i]->fonts = malloc
- (config->fonts[i]->sfont*sizeof(FcPattern *));
- buf = malloc (config->fonts[i]->sfont * sizeof(FcPattern));
- if (!config->fonts[i]->fonts || !buf)
- goto bail;
- for (j = 0; j < config->fonts[i]->nfont; j++)
- {
- config->fonts[i]->fonts[j] = buf+j;
- if (read(fd, buf+j, sizeof(FcPattern)) == -1)
- goto bail;
- }
- }
+ int sfont = s->nfont + nfont;
+ FcPattern ** pp;
+ pp = realloc (s->fonts, sfont * sizeof (FcPattern));
+ if (!pp)
+ return FcFalse;
+ s->fonts = pp;
+ s->sfont = sfont;
}
+ n = s->nfont;
+ s->nfont += nfont;
- return FcTrue;
- bail:
- for (i = FcSetSystem; i <= FcSetApplication; i++)
+ if (nfont > 0)
{
- if (config->fonts[i])
- {
- if (config->fonts[i]->fonts)
- free (config->fonts[i]->fonts);
- free(config->fonts[i]);
- }
- config->fonts[i] = 0;
+ FcPattern * p = FcPatternUnserialize (metadata, block_ptr);
+ for (i = 0; i < nfont; i++)
+ s->fonts[n + i] = p+i;
}
- return FcFalse;
-}
-FcBool
-FcFontSetWrite(int fd, FcConfig * config, FcCache * metadata)
-{
- int c, t, i, j;
- int m = FC_CACHE_MAGIC, z = 0;
-
- metadata->fontsets_offset = FcCacheNextOffset(fd);
- lseek(fd, metadata->fontsets_offset, SEEK_SET);
- for (i = FcSetSystem; i <= FcSetApplication; i++)
- {
- if (!config->fonts[i])
- {
- write(fd, &z, sizeof(int));
- continue;
- }
- else
- write(fd, &m, sizeof(int));
-
- if ((c = write(fd, config->fonts[i], sizeof(FcFontSet))) == -1)
- return FcFalse;
- t = c;
- if (config->fonts[i]->nfont > 0)
- {
- for (j = 0; j < config->fonts[i]->nfont; j++)
- {
- if ((c = write(fd, config->fonts[i]->fonts[j],
- sizeof(FcPattern))) == -1)
- return FcFalse;
- }
- }
- }
return FcTrue;
}