[xml] Allocate FcExpr's in a pool in FcConfig
Reduces number of malloc's for FcExprs from hundreds into single digits.
This commit is contained in:
parent
398d436441
commit
390c05e64a
32
src/fccfg.c
32
src/fccfg.c
|
@ -93,6 +93,8 @@ FcConfigCreate (void)
|
||||||
config->rescanTime = time(0);
|
config->rescanTime = time(0);
|
||||||
config->rescanInterval = 30;
|
config->rescanInterval = 30;
|
||||||
|
|
||||||
|
config->expr_pool = NULL;
|
||||||
|
|
||||||
config->ref = 1;
|
config->ref = 1;
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
@ -193,6 +195,26 @@ FcSubstDestroy (FcSubst *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FcExpr *
|
||||||
|
FcConfigAllocExpr (FcConfig *config)
|
||||||
|
{
|
||||||
|
if (!config->expr_pool || config->expr_pool->next == config->expr_pool->end)
|
||||||
|
{
|
||||||
|
FcExprPage *new_page;
|
||||||
|
|
||||||
|
new_page = malloc (sizeof (FcExprPage));
|
||||||
|
if (!new_page)
|
||||||
|
return 0;
|
||||||
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExprPage));
|
||||||
|
|
||||||
|
new_page->next_page = config->expr_pool;
|
||||||
|
new_page->next = new_page->exprs;
|
||||||
|
config->expr_pool = new_page;
|
||||||
|
}
|
||||||
|
|
||||||
|
return config->expr_pool->next++;
|
||||||
|
}
|
||||||
|
|
||||||
FcConfig *
|
FcConfig *
|
||||||
FcConfigReference (FcConfig *config)
|
FcConfigReference (FcConfig *config)
|
||||||
{
|
{
|
||||||
|
@ -212,6 +234,7 @@ void
|
||||||
FcConfigDestroy (FcConfig *config)
|
FcConfigDestroy (FcConfig *config)
|
||||||
{
|
{
|
||||||
FcSetName set;
|
FcSetName set;
|
||||||
|
FcExprPage *page;
|
||||||
|
|
||||||
if (--config->ref > 0)
|
if (--config->ref > 0)
|
||||||
return;
|
return;
|
||||||
|
@ -238,6 +261,15 @@ FcConfigDestroy (FcConfig *config)
|
||||||
if (config->fonts[set])
|
if (config->fonts[set])
|
||||||
FcFontSetDestroy (config->fonts[set]);
|
FcFontSetDestroy (config->fonts[set]);
|
||||||
|
|
||||||
|
page = config->expr_pool;
|
||||||
|
while (page)
|
||||||
|
{
|
||||||
|
FcExprPage *next = page->next_page;
|
||||||
|
FcMemFree (FC_MEM_EXPR, sizeof (FcExprPage));
|
||||||
|
free (page);
|
||||||
|
page = next;
|
||||||
|
}
|
||||||
|
|
||||||
free (config);
|
free (config);
|
||||||
FcMemFree (FC_MEM_CONFIG, sizeof (FcConfig));
|
FcMemFree (FC_MEM_CONFIG, sizeof (FcConfig));
|
||||||
}
|
}
|
||||||
|
|
14
src/fcint.h
14
src/fcint.h
|
@ -247,6 +247,15 @@ typedef struct _FcExpr {
|
||||||
} u;
|
} u;
|
||||||
} FcExpr;
|
} FcExpr;
|
||||||
|
|
||||||
|
typedef struct _FcExprPage FcExprPage;
|
||||||
|
|
||||||
|
struct _FcExprPage {
|
||||||
|
FcExprPage *next_page;
|
||||||
|
FcExpr *next;
|
||||||
|
FcExpr exprs[(1024 - 2/* two pointers */ - 2/* malloc overhead */) * sizeof (void *) / sizeof (FcExpr)];
|
||||||
|
FcExpr end[0];
|
||||||
|
};
|
||||||
|
|
||||||
typedef enum _FcQual {
|
typedef enum _FcQual {
|
||||||
FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
|
FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
|
||||||
} FcQual;
|
} FcQual;
|
||||||
|
@ -486,6 +495,8 @@ struct _FcConfig {
|
||||||
int rescanInterval; /* interval between scans */
|
int rescanInterval; /* interval between scans */
|
||||||
|
|
||||||
int ref; /* reference count */
|
int ref; /* reference count */
|
||||||
|
|
||||||
|
FcExprPage *expr_pool; /* pool of FcExpr's */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern FcPrivate FcConfig *_fcConfig;
|
extern FcPrivate FcConfig *_fcConfig;
|
||||||
|
@ -534,6 +545,9 @@ FcStat (const char *file, struct stat *statb)
|
||||||
|
|
||||||
/* fccfg.c */
|
/* fccfg.c */
|
||||||
|
|
||||||
|
FcPrivate FcExpr *
|
||||||
|
FcConfigAllocExpr (FcConfig *config);
|
||||||
|
|
||||||
FcPrivate FcBool
|
FcPrivate FcBool
|
||||||
FcConfigAddConfigDir (FcConfig *config,
|
FcConfigAddConfigDir (FcConfig *config,
|
||||||
const FcChar8 *d);
|
const FcChar8 *d);
|
||||||
|
|
75
src/fcxml.c
75
src/fcxml.c
|
@ -72,20 +72,9 @@ FcTestDestroy (FcTest *test)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcExpr *
|
static FcExpr *
|
||||||
FcExprAlloc (void)
|
FcExprCreateInteger (FcConfig *config, int i)
|
||||||
{
|
{
|
||||||
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
FcExpr *e = FcConfigAllocExpr (config);
|
||||||
|
|
||||||
if (e)
|
|
||||||
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
|
||||||
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FcExpr *
|
|
||||||
FcExprCreateInteger (int i)
|
|
||||||
{
|
|
||||||
FcExpr *e = FcExprAlloc ();
|
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e->op = FcOpInteger;
|
e->op = FcOpInteger;
|
||||||
|
@ -95,9 +84,9 @@ FcExprCreateInteger (int i)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcExpr *
|
static FcExpr *
|
||||||
FcExprCreateDouble (double d)
|
FcExprCreateDouble (FcConfig *config, double d)
|
||||||
{
|
{
|
||||||
FcExpr *e = FcExprAlloc ();
|
FcExpr *e = FcConfigAllocExpr (config);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e->op = FcOpDouble;
|
e->op = FcOpDouble;
|
||||||
|
@ -107,9 +96,9 @@ FcExprCreateDouble (double d)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcExpr *
|
static FcExpr *
|
||||||
FcExprCreateString (const FcChar8 *s)
|
FcExprCreateString (FcConfig *config, const FcChar8 *s)
|
||||||
{
|
{
|
||||||
FcExpr *e = FcExprAlloc ();
|
FcExpr *e = FcConfigAllocExpr (config);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e->op = FcOpString;
|
e->op = FcOpString;
|
||||||
|
@ -119,9 +108,9 @@ FcExprCreateString (const FcChar8 *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcExpr *
|
static FcExpr *
|
||||||
FcExprCreateMatrix (const FcMatrix *m)
|
FcExprCreateMatrix (FcConfig *config, const FcMatrix *m)
|
||||||
{
|
{
|
||||||
FcExpr *e = FcExprAlloc ();
|
FcExpr *e = FcConfigAllocExpr (config);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e->op = FcOpMatrix;
|
e->op = FcOpMatrix;
|
||||||
|
@ -131,9 +120,9 @@ FcExprCreateMatrix (const FcMatrix *m)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcExpr *
|
static FcExpr *
|
||||||
FcExprCreateBool (FcBool b)
|
FcExprCreateBool (FcConfig *config, FcBool b)
|
||||||
{
|
{
|
||||||
FcExpr *e = FcExprAlloc ();
|
FcExpr *e = FcConfigAllocExpr (config);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e->op = FcOpBool;
|
e->op = FcOpBool;
|
||||||
|
@ -143,9 +132,9 @@ FcExprCreateBool (FcBool b)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcExpr *
|
static FcExpr *
|
||||||
FcExprCreateNil (void)
|
FcExprCreateNil (FcConfig *config)
|
||||||
{
|
{
|
||||||
FcExpr *e = FcExprAlloc ();
|
FcExpr *e = FcConfigAllocExpr (config);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
||||||
|
@ -155,9 +144,9 @@ FcExprCreateNil (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcExpr *
|
static FcExpr *
|
||||||
FcExprCreateField (const char *field)
|
FcExprCreateField (FcConfig *config, const char *field)
|
||||||
{
|
{
|
||||||
FcExpr *e = FcExprAlloc ();
|
FcExpr *e = FcConfigAllocExpr (config);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e->op = FcOpField;
|
e->op = FcOpField;
|
||||||
|
@ -167,9 +156,9 @@ FcExprCreateField (const char *field)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcExpr *
|
static FcExpr *
|
||||||
FcExprCreateConst (const FcChar8 *constant)
|
FcExprCreateConst (FcConfig *config, const FcChar8 *constant)
|
||||||
{
|
{
|
||||||
FcExpr *e = FcExprAlloc ();
|
FcExpr *e = FcConfigAllocExpr (config);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e->op = FcOpConst;
|
e->op = FcOpConst;
|
||||||
|
@ -179,9 +168,9 @@ FcExprCreateConst (const FcChar8 *constant)
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcExpr *
|
static FcExpr *
|
||||||
FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right)
|
FcExprCreateOp (FcConfig *config, FcExpr *left, FcOp op, FcExpr *right)
|
||||||
{
|
{
|
||||||
FcExpr *e = FcExprAlloc ();
|
FcExpr *e = FcConfigAllocExpr (config);
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
e->op = op;
|
e->op = op;
|
||||||
|
@ -254,8 +243,8 @@ FcExprDestroy (FcExpr *e)
|
||||||
case FcOpInvalid:
|
case FcOpInvalid:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
FcMemFree (FC_MEM_EXPR, sizeof (FcExpr));
|
|
||||||
free (e);
|
e->op = FcOpNil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1337,7 +1326,7 @@ FcParseFamilies (FcConfigParse *parse, FcVStackTag tag)
|
||||||
FcVStackPopAndDestroy (parse);
|
FcVStackPopAndDestroy (parse);
|
||||||
if (expr)
|
if (expr)
|
||||||
{
|
{
|
||||||
new = FcExprCreateOp (left, FcOpComma, expr);
|
new = FcExprCreateOp (parse->config, left, FcOpComma, expr);
|
||||||
if (!new)
|
if (!new)
|
||||||
{
|
{
|
||||||
FcConfigMessage (parse, FcSevereError, "out of memory");
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
||||||
|
@ -1374,7 +1363,7 @@ FcParseFamily (FcConfigParse *parse)
|
||||||
FcConfigMessage (parse, FcSevereError, "out of memory");
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
expr = FcExprCreateString (s);
|
expr = FcExprCreateString (parse->config, s);
|
||||||
FcStrBufDestroy (&parse->pstack->str);
|
FcStrBufDestroy (&parse->pstack->str);
|
||||||
if (expr)
|
if (expr)
|
||||||
FcVStackPushExpr (parse, FcVStackFamily, expr);
|
FcVStackPushExpr (parse, FcVStackFamily, expr);
|
||||||
|
@ -1397,7 +1386,7 @@ FcParseAlias (FcConfigParse *parse)
|
||||||
case FcVStackFamily:
|
case FcVStackFamily:
|
||||||
if (family)
|
if (family)
|
||||||
{
|
{
|
||||||
new = FcExprCreateOp (vstack->u.expr, FcOpComma, family);
|
new = FcExprCreateOp (parse->config, vstack->u.expr, FcOpComma, family);
|
||||||
if (!new)
|
if (!new)
|
||||||
FcConfigMessage (parse, FcSevereError, "out of memory");
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
||||||
else
|
else
|
||||||
|
@ -1511,13 +1500,13 @@ FcPopExpr (FcConfigParse *parse)
|
||||||
break;
|
break;
|
||||||
case FcVStackString:
|
case FcVStackString:
|
||||||
case FcVStackFamily:
|
case FcVStackFamily:
|
||||||
expr = FcExprCreateString (vstack->u.string);
|
expr = FcExprCreateString (parse->config, vstack->u.string);
|
||||||
break;
|
break;
|
||||||
case FcVStackField:
|
case FcVStackField:
|
||||||
expr = FcExprCreateField ((char *) vstack->u.string);
|
expr = FcExprCreateField (parse->config, (char *) vstack->u.string);
|
||||||
break;
|
break;
|
||||||
case FcVStackConstant:
|
case FcVStackConstant:
|
||||||
expr = FcExprCreateConst (vstack->u.string);
|
expr = FcExprCreateConst (parse->config, vstack->u.string);
|
||||||
break;
|
break;
|
||||||
case FcVStackGlob:
|
case FcVStackGlob:
|
||||||
/* XXX: What's the correct action here? (CDW) */
|
/* XXX: What's the correct action here? (CDW) */
|
||||||
|
@ -1529,16 +1518,16 @@ FcPopExpr (FcConfigParse *parse)
|
||||||
vstack->tag = FcVStackNone;
|
vstack->tag = FcVStackNone;
|
||||||
break;
|
break;
|
||||||
case FcVStackInteger:
|
case FcVStackInteger:
|
||||||
expr = FcExprCreateInteger (vstack->u.integer);
|
expr = FcExprCreateInteger (parse->config, vstack->u.integer);
|
||||||
break;
|
break;
|
||||||
case FcVStackDouble:
|
case FcVStackDouble:
|
||||||
expr = FcExprCreateDouble (vstack->u._double);
|
expr = FcExprCreateDouble (parse->config, vstack->u._double);
|
||||||
break;
|
break;
|
||||||
case FcVStackMatrix:
|
case FcVStackMatrix:
|
||||||
expr = FcExprCreateMatrix (vstack->u.matrix);
|
expr = FcExprCreateMatrix (parse->config, vstack->u.matrix);
|
||||||
break;
|
break;
|
||||||
case FcVStackBool:
|
case FcVStackBool:
|
||||||
expr = FcExprCreateBool (vstack->u.bool_);
|
expr = FcExprCreateBool (parse->config, vstack->u.bool_);
|
||||||
break;
|
break;
|
||||||
case FcVStackTest:
|
case FcVStackTest:
|
||||||
break;
|
break;
|
||||||
|
@ -1573,7 +1562,7 @@ FcPopBinary (FcConfigParse *parse, FcOp op)
|
||||||
{
|
{
|
||||||
if (expr)
|
if (expr)
|
||||||
{
|
{
|
||||||
new = FcExprCreateOp (left, op, expr);
|
new = FcExprCreateOp (parse->config, left, op, expr);
|
||||||
if (!new)
|
if (!new)
|
||||||
{
|
{
|
||||||
FcConfigMessage (parse, FcSevereError, "out of memory");
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
||||||
|
@ -1609,7 +1598,7 @@ FcPopUnary (FcConfigParse *parse, FcOp op)
|
||||||
|
|
||||||
if ((operand = FcPopExpr (parse)))
|
if ((operand = FcPopExpr (parse)))
|
||||||
{
|
{
|
||||||
new = FcExprCreateOp (operand, op, 0);
|
new = FcExprCreateOp (parse->config, operand, op, 0);
|
||||||
if (!new)
|
if (!new)
|
||||||
{
|
{
|
||||||
FcExprDestroy (operand);
|
FcExprDestroy (operand);
|
||||||
|
|
Loading…
Reference in New Issue