/*
- * $XFree86: xc/lib/fontconfig/src/fccharset.c,v 1.16 2002/07/09 02:28:29 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fccharset.c,v 1.17 2002/07/13 05:43:25 keithp Exp $
*
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
*
fcs->num = 0;
fcs->leaves = 0;
fcs->numbers = 0;
- fcs->constant = FcFalse;
return fcs;
}
void
FcCharSetDestroy (FcCharSet *fcs)
{
- if (!fcs->constant && --fcs->ref <= 0)
+ int i;
+ if (fcs->ref == FC_REF_CONSTANT)
+ return;
+ if (--fcs->ref > 0)
+ return;
+ for (i = 0; i < fcs->num; i++)
{
- int i;
-
- for (i = 0; i < fcs->num; i++)
- {
- FcMemFree (FC_MEM_CHARNODE, sizeof (FcCharLeaf));
- free (fcs->leaves[i]);
- }
- if (fcs->leaves)
- {
- FcMemFree (FC_MEM_CHARSET, fcs->num * sizeof (FcCharLeaf *));
- free (fcs->leaves);
- }
- if (fcs->numbers)
- {
- FcMemFree (FC_MEM_CHARSET, fcs->num * sizeof (FcChar16));
- free (fcs->numbers);
- }
- FcMemFree (FC_MEM_CHARSET, sizeof (FcCharSet));
- free (fcs);
+ FcMemFree (FC_MEM_CHARLEAF, sizeof (FcCharLeaf));
+ free (fcs->leaves[i]);
+ }
+ if (fcs->leaves)
+ {
+ FcMemFree (FC_MEM_CHARSET, fcs->num * sizeof (FcCharLeaf *));
+ free (fcs->leaves);
}
+ if (fcs->numbers)
+ {
+ FcMemFree (FC_MEM_CHARSET, fcs->num * sizeof (FcChar16));
+ free (fcs->numbers);
+ }
+ FcMemFree (FC_MEM_CHARSET, sizeof (FcCharSet));
+ free (fcs);
}
/*
leaves = realloc (fcs->leaves, (fcs->num + 1) * sizeof (FcCharLeaf *));
if (!leaves)
return FcFalse;
+ FcMemAlloc (FC_MEM_CHARSET, sizeof (FcCharLeaf *));
fcs->leaves = leaves;
if (!fcs->numbers)
numbers = malloc (sizeof (FcChar16));
numbers = realloc (fcs->numbers, (fcs->num + 1) * sizeof (FcChar16));
if (!numbers)
return FcFalse;
+ FcMemAlloc (FC_MEM_CHARSET, sizeof (FcChar16));
fcs->numbers = numbers;
memmove (fcs->leaves + pos + 1, fcs->leaves + pos,
free (leaf);
return 0;
}
+ FcMemAlloc (FC_MEM_CHARLEAF, sizeof (FcCharLeaf));
return leaf;
}
pos = FcCharSetFindLeafPos (fcs, ucs4);
if (pos >= 0)
{
- FcMemAlloc (FC_MEM_CHARNODE, sizeof (FcCharLeaf));
+ FcMemFree (FC_MEM_CHARLEAF, sizeof (FcCharLeaf));
free (fcs->leaves[pos]);
fcs->leaves[pos] = leaf;
return FcTrue;
FcCharLeaf *leaf;
FcChar32 *b;
- if (fcs->constant)
+ if (fcs->ref == FC_REF_CONSTANT)
return FcFalse;
leaf = FcCharSetFindLeafCreate (fcs, ucs4);
if (!leaf)
FcCharSet *
FcCharSetCopy (FcCharSet *src)
{
- src->ref++;
+ if (src->ref != FC_REF_CONSTANT)
+ src->ref++;
return src;
}
block = malloc (FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt));
if (!block)
return 0;
+ FcMemAlloc (FC_MEM_CHARLEAF, FC_CHAR_LEAF_BLOCK * sizeof (FcCharLeafEnt));
remain = FC_CHAR_LEAF_BLOCK;
}
remain--;
FcChar32 hash = FcCharSetHash (fcs);
FcCharSetEnt **bucket = &hashTable[hash % FC_CHAR_SET_HASH_SIZE];
FcCharSetEnt *ent;
+ int size;
FcCharSetTotal++;
FcCharSetTotalEnts += fcs->num;
}
}
- ent = malloc (sizeof (FcCharSetEnt) +
- fcs->num * sizeof (FcCharLeaf *) +
- fcs->num * sizeof (FcChar16));
+ size = (sizeof (FcCharSetEnt) +
+ fcs->num * sizeof (FcCharLeaf *) +
+ fcs->num * sizeof (FcChar16));
+ ent = malloc (size);
if (!ent)
return 0;
+ FcMemAlloc (FC_MEM_CHARSET, size);
FcCharSetUsed++;
FcCharSetUsedEnts += fcs->num;
- ent->set.ref = 0;
- ent->set.constant = FcTrue;
+ ent->set.ref = FC_REF_CONSTANT;
ent->set.num = fcs->num;
if (fcs->num)
{
n = FcCharSetFreezeBase (b);
bail1:
if (b->leaves)
+ {
+ FcMemFree (FC_MEM_CHARSET, b->num * sizeof (FcCharLeaf *));
free (b->leaves);
+ }
if (b->numbers)
+ {
+ FcMemFree (FC_MEM_CHARSET, b->num * sizeof (FcChar16));
free (b->numbers);
+ }
+ FcMemFree (FC_MEM_CHARSET, sizeof (FcCharSet));
free (b);
bail0:
return n;
n = FcCharSetFreezeBase (c);
bail1:
if (c->leaves)
+ {
+ FcMemFree (FC_MEM_CHARSET, c->num * sizeof (FcCharLeaf *));
free (c->leaves);
+ }
if (c->numbers)
+ {
+ FcMemFree (FC_MEM_CHARSET, c->num * sizeof (FcChar16));
free (c->numbers);
+ }
+ FcMemFree (FC_MEM_CHARSET, sizeof (FcCharSet));
free (c);
bail0:
return n;