]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/letest/FontTableCache.cpp
2 **********************************************************************
3 * Copyright (C) 2003-2006, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
8 #include "layout/LETypes.h"
11 #include "FontTableCache.h"
13 #define TABLE_CACHE_INIT 5
14 #define TABLE_CACHE_GROW 5
16 struct FontTableCacheEntry
22 FontTableCache::FontTableCache()
23 : fTableCacheCurr(0), fTableCacheSize(TABLE_CACHE_INIT
)
25 fTableCache
= NEW_ARRAY(FontTableCacheEntry
, fTableCacheSize
);
27 if (fTableCache
== NULL
) {
32 for (int i
= 0; i
< fTableCacheSize
; i
+= 1) {
33 fTableCache
[i
].tag
= 0;
34 fTableCache
[i
].table
= NULL
;
38 FontTableCache::~FontTableCache()
40 for (int i
= fTableCacheCurr
- 1; i
>= 0; i
-= 1) {
41 DELETE_ARRAY(fTableCache
[i
].table
);
43 fTableCache
[i
].tag
= 0;
44 fTableCache
[i
].table
= NULL
;
49 DELETE_ARRAY(fTableCache
);
52 const void *FontTableCache::find(LETag tableTag
) const
54 for (int i
= 0; i
< fTableCacheCurr
; i
+= 1) {
55 if (fTableCache
[i
].tag
== tableTag
) {
56 return fTableCache
[i
].table
;
60 const void *table
= readFontTable(tableTag
);
62 ((FontTableCache
*) this)->add(tableTag
, table
);
67 void FontTableCache::add(LETag tableTag
, const void *table
)
69 if (fTableCacheCurr
>= fTableCacheSize
) {
70 le_int32 newSize
= fTableCacheSize
+ TABLE_CACHE_GROW
;
72 fTableCache
= (FontTableCacheEntry
*) GROW_ARRAY(fTableCache
, newSize
);
74 for (le_int32 i
= fTableCacheSize
; i
< newSize
; i
+= 1) {
75 fTableCache
[i
].tag
= 0;
76 fTableCache
[i
].table
= NULL
;
79 fTableCacheSize
= newSize
;
82 fTableCache
[fTableCacheCurr
].tag
= tableTag
;
83 fTableCache
[fTableCacheCurr
].table
= table
;