X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..ef6cf650f4a75c3f97de06b51fa104f2069b9ea2:/icuSources/test/letest/FontTableCache.cpp diff --git a/icuSources/test/letest/FontTableCache.cpp b/icuSources/test/letest/FontTableCache.cpp index cf28de22..a2c0727a 100644 --- a/icuSources/test/letest/FontTableCache.cpp +++ b/icuSources/test/letest/FontTableCache.cpp @@ -1,13 +1,13 @@ /* ********************************************************************** - * Copyright (C) 2003-2006, International Business Machines + * Copyright (C) 2003-2013, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** */ #include "layout/LETypes.h" -#include "letest.h" +//#include "letest.h" #include "FontTableCache.h" #define TABLE_CACHE_INIT 5 @@ -15,14 +15,15 @@ struct FontTableCacheEntry { - LETag tag; - const void *table; + LETag tag; + const void *table; + size_t length; }; FontTableCache::FontTableCache() : fTableCacheCurr(0), fTableCacheSize(TABLE_CACHE_INIT) { - fTableCache = NEW_ARRAY(FontTableCacheEntry, fTableCacheSize); + fTableCache = LE_NEW_ARRAY(FontTableCacheEntry, fTableCacheSize); if (fTableCache == NULL) { fTableCacheSize = 0; @@ -32,48 +33,57 @@ FontTableCache::FontTableCache() for (int i = 0; i < fTableCacheSize; i += 1) { fTableCache[i].tag = 0; fTableCache[i].table = NULL; + fTableCache[i].length = 0; } } FontTableCache::~FontTableCache() { for (int i = fTableCacheCurr - 1; i >= 0; i -= 1) { - DELETE_ARRAY(fTableCache[i].table); + LE_DELETE_ARRAY(fTableCache[i].table); fTableCache[i].tag = 0; fTableCache[i].table = NULL; + fTableCache[i].length = 0; } fTableCacheCurr = 0; - DELETE_ARRAY(fTableCache); + LE_DELETE_ARRAY(fTableCache); } -const void *FontTableCache::find(LETag tableTag) const +void FontTableCache::freeFontTable(const void *table) const +{ + LE_DELETE_ARRAY(table); +} + +const void *FontTableCache::find(LETag tableTag, size_t &length) const { for (int i = 0; i < fTableCacheCurr; i += 1) { if (fTableCache[i].tag == tableTag) { - return fTableCache[i].table; + length = fTableCache[i].length; + return fTableCache[i].table; } } - const void *table = readFontTable(tableTag); + const void *table = readFontTable(tableTag, length); - ((FontTableCache *) this)->add(tableTag, table); + ((FontTableCache *) this)->add(tableTag, table, length); return table; } -void FontTableCache::add(LETag tableTag, const void *table) +void FontTableCache::add(LETag tableTag, const void *table, size_t length) { if (fTableCacheCurr >= fTableCacheSize) { le_int32 newSize = fTableCacheSize + TABLE_CACHE_GROW; - fTableCache = (FontTableCacheEntry *) GROW_ARRAY(fTableCache, newSize); + fTableCache = (FontTableCacheEntry *) LE_GROW_ARRAY(fTableCache, newSize); for (le_int32 i = fTableCacheSize; i < newSize; i += 1) { fTableCache[i].tag = 0; fTableCache[i].table = NULL; + fTableCache[i].length = 0; } fTableCacheSize = newSize; @@ -81,6 +91,7 @@ void FontTableCache::add(LETag tableTag, const void *table) fTableCache[fTableCacheCurr].tag = tableTag; fTableCache[fTableCacheCurr].table = table; + fTableCache[fTableCacheCurr].length = length; fTableCacheCurr += 1; }