Skip to content

Commit 972405b

Browse files
committed
Updated subproject glyphcache_bench: enabled FONT_LOCAL_GLYPH_CACHE_GUARD & FONT_GLYPH_CACHE_GUARD
in all cache implementation, enabled global cache refresh in experimental cache based on hash table, so that the performance comparison is correct.
1 parent 2d47e03 commit 972405b

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

crengine/Tools/glyphcache_bench/lvfontglyphcache_a.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
// This file contains copy of class LVFontLocalGlyphCacheA from cr3.2.31
1616

1717
#include "lvfontglyphcache_a.h"
18-
//#include "../../include/crlocks.h"
18+
#include "../../include/crlocks.h"
1919

2020

2121
void LVFontLocalGlyphCacheA::clear() {
22-
//FONT_LOCAL_GLYPH_CACHE_GUARD
22+
FONT_LOCAL_GLYPH_CACHE_GUARD
2323
while (head) {
2424
LVFontGlyphCacheItemA *ptr = head;
2525
remove(ptr);
@@ -29,7 +29,7 @@ void LVFontLocalGlyphCacheA::clear() {
2929
}
3030

3131
LVFontGlyphCacheItemA *LVFontLocalGlyphCacheA::getByChar(lChar16 ch) {
32-
//FONT_LOCAL_GLYPH_CACHE_GUARD
32+
FONT_LOCAL_GLYPH_CACHE_GUARD
3333
LVFontGlyphCacheItemA *ptr = head;
3434
for (; ptr; ptr = ptr->next_local) {
3535
if (ptr->data.ch == ch) {
@@ -43,7 +43,7 @@ LVFontGlyphCacheItemA *LVFontLocalGlyphCacheA::getByChar(lChar16 ch) {
4343
#if USE_HARFBUZZ==1
4444
LVFontGlyphCacheItemA* LVFontLocalGlyphCacheA::getByIndex(lUInt32 index)
4545
{
46-
//FONT_LOCAL_GLYPH_CACHE_GUARD
46+
FONT_LOCAL_GLYPH_CACHE_GUARD
4747
LVFontGlyphCacheItemA *ptr = head;
4848
for (; ptr; ptr = ptr->next_local) {
4949
if (ptr->data.gindex == index) {
@@ -56,7 +56,7 @@ LVFontGlyphCacheItemA* LVFontLocalGlyphCacheA::getByIndex(lUInt32 index)
5656
#endif
5757

5858
void LVFontLocalGlyphCacheA::put(LVFontGlyphCacheItemA *item) {
59-
//FONT_LOCAL_GLYPH_CACHE_GUARD
59+
FONT_LOCAL_GLYPH_CACHE_GUARD
6060
global_cache->put(item);
6161
item->next_local = head;
6262
if (head)
@@ -68,7 +68,7 @@ void LVFontLocalGlyphCacheA::put(LVFontGlyphCacheItemA *item) {
6868

6969
/// remove from list, but don't delete
7070
void LVFontLocalGlyphCacheA::remove(LVFontGlyphCacheItemA *item) {
71-
//FONT_LOCAL_GLYPH_CACHE_GUARD
71+
FONT_LOCAL_GLYPH_CACHE_GUARD
7272
if (item == head)
7373
head = item->next_local;
7474
if (item == tail)
@@ -84,7 +84,7 @@ void LVFontLocalGlyphCacheA::remove(LVFontGlyphCacheItemA *item) {
8484
}
8585

8686
void LVFontGlobalGlyphCacheA::refresh(LVFontGlyphCacheItemA *item) {
87-
//FONT_GLYPH_CACHE_GUARD
87+
FONT_GLYPH_CACHE_GUARD
8888
if (tail != item) {
8989
//move to head
9090
removeNoLock(item);
@@ -93,7 +93,7 @@ void LVFontGlobalGlyphCacheA::refresh(LVFontGlyphCacheItemA *item) {
9393
}
9494

9595
void LVFontGlobalGlyphCacheA::put(LVFontGlyphCacheItemA *item) {
96-
//FONT_GLYPH_CACHE_GUARD
96+
FONT_GLYPH_CACHE_GUARD
9797
putNoLock(item);
9898
}
9999

@@ -119,7 +119,7 @@ void LVFontGlobalGlyphCacheA::putNoLock(LVFontGlyphCacheItemA *item) {
119119
}
120120

121121
void LVFontGlobalGlyphCacheA::remove(LVFontGlyphCacheItemA *item) {
122-
//FONT_GLYPH_CACHE_GUARD
122+
FONT_GLYPH_CACHE_GUARD
123123
removeNoLock(item);
124124
}
125125

@@ -140,7 +140,7 @@ void LVFontGlobalGlyphCacheA::removeNoLock(LVFontGlyphCacheItemA *item) {
140140
}
141141

142142
void LVFontGlobalGlyphCacheA::clear() {
143-
//FONT_GLYPH_CACHE_GUARD
143+
FONT_GLYPH_CACHE_GUARD
144144
while (head) {
145145
LVFontGlyphCacheItemA *ptr = head;
146146
remove(ptr);

crengine/Tools/glyphcache_bench/lvfontglyphcache_b.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
#include "lvfontglyphcache_b.h"
16-
//#include "../../include/crlocks.h"
16+
#include "../../include/crlocks.h"
1717
#include <stdio.h>
1818

1919

@@ -28,7 +28,7 @@ inline bool operator==(GlyphCacheItemData data1, GlyphCacheItemData data2)
2828
}
2929

3030
void LVFontLocalGlyphCacheB::clear() {
31-
//FONT_LOCAL_GLYPH_CACHE_GUARD
31+
FONT_LOCAL_GLYPH_CACHE_GUARD
3232
int count = 0;
3333
LVHashTable<GlyphCacheItemData, struct LVFontGlyphCacheItemB*>::iterator it = hashTable.forwardIterator();
3434
LVHashTable<GlyphCacheItemData, struct LVFontGlyphCacheItemB*>::pair* pair;
@@ -43,12 +43,13 @@ void LVFontLocalGlyphCacheB::clear() {
4343
}
4444

4545
LVFontGlyphCacheItemB *LVFontLocalGlyphCacheB::getByChar(lChar16 ch) {
46-
//FONT_LOCAL_GLYPH_CACHE_GUARD
46+
FONT_LOCAL_GLYPH_CACHE_GUARD
4747
LVFontGlyphCacheItemB *ptr = 0;
4848
GlyphCacheItemData data;
4949
data.ch = ch;
5050
if (hashTable.get(data, ptr))
5151
{
52+
global_cache->refresh(ptr);
5253
return ptr;
5354
}
5455
return NULL;
@@ -57,32 +58,42 @@ LVFontGlyphCacheItemB *LVFontLocalGlyphCacheB::getByChar(lChar16 ch) {
5758
#if USE_HARFBUZZ==1
5859
LVFontGlyphCacheItemB* LVFontLocalGlyphCacheB::getByIndex(lUInt32 index)
5960
{
60-
//FONT_LOCAL_GLYPH_CACHE_GUARD
61+
FONT_LOCAL_GLYPH_CACHE_GUARD
6162
LVFontGlyphCacheItemB *ptr = 0;
6263
GlyphCacheItemData data;
6364
data.gindex = index;
6465
if (hashTable.get(data, ptr))
6566
{
67+
global_cache->refresh(ptr);
6668
return ptr;
6769
}
6870
return NULL;
6971
}
7072
#endif
7173

7274
void LVFontLocalGlyphCacheB::put(LVFontGlyphCacheItemB *item) {
73-
//FONT_LOCAL_GLYPH_CACHE_GUARD
75+
FONT_LOCAL_GLYPH_CACHE_GUARD
7476
global_cache->put(item);
7577
hashTable.set(item->data, item);
7678
}
7779

7880
/// remove hash table, but don't delete
7981
void LVFontLocalGlyphCacheB::remove(LVFontGlyphCacheItemB *item) {
80-
//FONT_LOCAL_GLYPH_CACHE_GUARD
82+
FONT_LOCAL_GLYPH_CACHE_GUARD
8183
hashTable.remove(item->data);
8284
}
8385

86+
void LVFontGlobalGlyphCacheB::refresh(LVFontGlyphCacheItemB *item) {
87+
FONT_GLYPH_CACHE_GUARD
88+
if (tail != item) {
89+
//move to head
90+
removeNoLock(item);
91+
putNoLock(item);
92+
}
93+
}
94+
8495
void LVFontGlobalGlyphCacheB::put(LVFontGlyphCacheItemB *item) {
85-
//FONT_GLYPH_CACHE_GUARD
96+
FONT_GLYPH_CACHE_GUARD
8697
putNoLock(item);
8798
}
8899

@@ -108,7 +119,7 @@ void LVFontGlobalGlyphCacheB::putNoLock(LVFontGlyphCacheItemB *item) {
108119
}
109120

110121
void LVFontGlobalGlyphCacheB::remove(LVFontGlyphCacheItemB *item) {
111-
//FONT_GLYPH_CACHE_GUARD
122+
FONT_GLYPH_CACHE_GUARD
112123
removeNoLock(item);
113124
}
114125

@@ -129,7 +140,7 @@ void LVFontGlobalGlyphCacheB::removeNoLock(LVFontGlyphCacheItemB *item) {
129140
}
130141

131142
void LVFontGlobalGlyphCacheB::clear() {
132-
//FONT_GLYPH_CACHE_GUARD
143+
FONT_GLYPH_CACHE_GUARD
133144
int count = 0;
134145
while (head) {
135146
LVFontGlyphCacheItemB *ptr = head;

crengine/Tools/glyphcache_bench/lvfontglyphcache_b.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class LVFontGlobalGlyphCacheB {
5353

5454
void remove(LVFontGlyphCacheItemB *item);
5555

56+
void refresh(LVFontGlyphCacheItemB *item);
57+
5658
void clear();
5759

5860
int getSize() { return size; }

crengine/Tools/glyphcache_bench/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ int main(int /*argc*/, char* /*argv*/[])
278278
LVFontLocalGlyphCache localCache(&globalCache);
279279
LVFontGlyphCacheItem* item;
280280

281-
uint64_t tmp;
281+
volatile uint64_t tmp;
282282
struct timeval ts1;
283283
struct timeval ts2;
284284
int64_t elapsed;
@@ -334,7 +334,7 @@ int main(int /*argc*/, char* /*argv*/[])
334334
printf("t = %lld\n", tmp);
335335

336336
// bench lookup based on hash table
337-
printf("bench cache based on hash table (copy from cr3.2.32)...\n");
337+
printf("bench cache based on hash table (candidate introduced in cr3.2.32)...\n");
338338
gettimeofday(&ts1, NULL);
339339
for (j = 0; j < bench_sz; j++)
340340
{

0 commit comments

Comments
 (0)