]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/leperf/FontTableCache.cpp
b3124326ee0d88f5c09e7d6884d22c69b6e1438e
2 **************************************************************************
3 * © 2016 and later: Unicode, Inc. and others.
4 * License & terms of use: http://www.unicode.org/copyright.html#License
5 *************************************************************************
6 *************************************************************************
7 * Copyright (C) 2003-2013, International Business Machines
8 * Corporation and others. All Rights Reserved.
9 *************************************************************************
12 #include "layout/LETypes.h"
15 #include "FontTableCache.h"
17 #define TABLE_CACHE_INIT 5
18 #define TABLE_CACHE_GROW 5
20 struct FontTableCacheEntry
27 FontTableCache::FontTableCache()
28 : fTableCacheCurr(0), fTableCacheSize(TABLE_CACHE_INIT
)
30 fTableCache
= LE_NEW_ARRAY(FontTableCacheEntry
, fTableCacheSize
);
32 if (fTableCache
== NULL
) {
37 for (int i
= 0; i
< fTableCacheSize
; i
+= 1) {
38 fTableCache
[i
].tag
= 0;
39 fTableCache
[i
].table
= NULL
;
40 fTableCache
[i
].length
= 0;
44 FontTableCache::~FontTableCache()
46 for (int i
= fTableCacheCurr
- 1; i
>= 0; i
-= 1) {
47 LE_DELETE_ARRAY(fTableCache
[i
].table
);
49 fTableCache
[i
].tag
= 0;
50 fTableCache
[i
].table
= NULL
;
51 fTableCache
[i
].length
= 0;
56 LE_DELETE_ARRAY(fTableCache
);
59 void FontTableCache::freeFontTable(const void *table
) const
61 LE_DELETE_ARRAY(table
);
64 const void *FontTableCache::find(LETag tableTag
, size_t &length
) const
66 for (int i
= 0; i
< fTableCacheCurr
; i
+= 1) {
67 if (fTableCache
[i
].tag
== tableTag
) {
68 length
= fTableCache
[i
].length
;
69 return fTableCache
[i
].table
;
73 const void *table
= readFontTable(tableTag
, length
);
75 ((FontTableCache
*) this)->add(tableTag
, table
, length
);
80 void FontTableCache::add(LETag tableTag
, const void *table
, size_t length
)
82 if (fTableCacheCurr
>= fTableCacheSize
) {
83 le_int32 newSize
= fTableCacheSize
+ TABLE_CACHE_GROW
;
85 fTableCache
= (FontTableCacheEntry
*) LE_GROW_ARRAY(fTableCache
, newSize
);
87 for (le_int32 i
= fTableCacheSize
; i
< newSize
; i
+= 1) {
88 fTableCache
[i
].tag
= 0;
89 fTableCache
[i
].table
= NULL
;
90 fTableCache
[i
].length
= 0;
93 fTableCacheSize
= newSize
;
96 fTableCache
[fTableCacheCurr
].tag
= tableTag
;
97 fTableCache
[fTableCacheCurr
].table
= table
;
98 fTableCache
[fTableCacheCurr
].length
= length
;
100 fTableCacheCurr
+= 1;