From 516b96387b0e57b524a37a96da22dbeeeb041712 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 30 Jul 2007 17:31:47 -0700 Subject: ProcRenderAddGlyphs: Avoid allocating a glyph just to find it cached This is a cleanup without any real savings (yet). Previously, the implementation would allocate a new glyph, then (often) find it in the cache, and immediately discard the allocated object. This re-organization first uses a new FindGlyphByHash function and only allocates the glyph if nothing is found. This isn't a real savings yet, since FindGlyphByHash currently still does a temporary glyph allocation, but this is expected to be replaced immediately as we switch to an alternate hashing mechanism (SHA1). --- render/glyph.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'render/glyph.c') diff --git a/render/glyph.c b/render/glyph.c index 53c00b326..1204c3b79 100644 --- a/render/glyph.c +++ b/render/glyph.c @@ -490,6 +490,31 @@ HashGlyph (GlyphPtr glyph) glyph->size - sizeof (xGlyphInfo)); } +GlyphPtr +FindGlyphByHash (CARD32 hash, + xGlyphInfo *gi, + CARD8 *bits, + int format) +{ + GlyphRefPtr gr; + GlyphPtr template; + + /* XXX: Should handle out-of-memory here */ + template = AllocateGlyph (gi, format); + memcpy ((CARD8 *) (template + 1), bits, + template->size - sizeof (xGlyphInfo)); + + gr = FindGlyphRef (&globalGlyphs[format], + hash, TRUE, template); + + xfree (template); + + if (gr->glyph && gr->glyph != DeletedGlyph) + return gr->glyph; + else + return NULL; +} + #ifdef CHECK_DUPLICATES void DuplicateRef (GlyphPtr glyph, char *where) @@ -572,7 +597,7 @@ AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id) /* Locate existing matching glyph */ hash = HashGlyph (glyph); gr = FindGlyphRef (&globalGlyphs[glyphSet->fdepth], hash, TRUE, glyph); - if (gr->glyph && gr->glyph != DeletedGlyph) + if (gr->glyph && gr->glyph != DeletedGlyph && gr->glyph != glyph) { PictureScreenPtr ps; int i; @@ -588,7 +613,7 @@ AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id) xfree (glyph); glyph = gr->glyph; } - else + else if (gr->glyph != glyph) { gr->glyph = glyph; gr->signature = hash; -- cgit v1.2.3