Skip to content

Commit 9870c9a

Browse files
committed
Merge remote-tracking branch 'upstream/cr3.2.33-fixes'
2 parents 9994284 + 972405b commit 9870c9a

File tree

8 files changed

+83
-26
lines changed

8 files changed

+83
-26
lines changed

android/src/org/coolreader/crengine/ReaderView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,8 @@ private BitmapInfo preparePageImage(int offset) {
38293829
return currentImageViewer.prepareImage();
38303830

38313831
PositionProperties currpos = doc.getPositionProps(null);
3832+
if (null == currpos)
3833+
return null;
38323834

38333835
boolean isPageView = currpos.pageMode!=0;
38343836

crengine/Tools/glyphcache_bench/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ set(SRC_LIST
55
lvfontglyphcache_b.cpp
66
)
77

8+
set(crengine_part_SRC_LIST
9+
../../src/crconcurrent.cpp
10+
../../src/lvstring.cpp
11+
../../src/lvmemman.cpp
12+
../../src/lvstream.cpp
13+
../../src/crtxtenc.cpp
14+
../../src/cp_stats.cpp
15+
../../src/private/lvfontglyphcache.cpp
16+
)
17+
818
if(WIN32)
919
add_definitions(-DWIN32 -D_CONSOLE)
1020
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mconsole")
1121
endif(WIN32)
1222

13-
add_executable(glyphcache_bench ${SRC_LIST})
14-
#target_link_libraries(glyphcache_bench)
23+
add_executable(glyphcache_bench ${SRC_LIST} ${crengine_part_SRC_LIST})
24+
target_link_libraries(glyphcache_bench ${ZLIB_LIBRARIES})
1525

1626
configure_file(valgrind_check.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/valgrind_check.sh)

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: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

22
#include "lvfontglyphcache_a.h"
33
#include "lvfontglyphcache_b.h"
4+
#include "../../src/private/lvfontglyphcache.h"
45
#include "lvtypes.h"
56

67
#include <stdio.h>
8+
#include <stdint.h>
79
#include <sys/time.h>
810
#include <limits.h>
911

@@ -271,7 +273,12 @@ int main(int /*argc*/, char* /*argv*/[])
271273
LVFontGlobalGlyphCacheB globalCacheB(0x40000);
272274
LVFontLocalGlyphCacheB localCacheB(&globalCacheB, 256);
273275
LVFontGlyphCacheItemB* itemB;
274-
u_int64_t tmp;
276+
277+
LVFontGlobalGlyphCache globalCache(0x40000);
278+
LVFontLocalGlyphCache localCache(&globalCache);
279+
LVFontGlyphCacheItem* item;
280+
281+
volatile uint64_t tmp;
275282
struct timeval ts1;
276283
struct timeval ts2;
277284
int64_t elapsed;
@@ -296,10 +303,18 @@ int main(int /*argc*/, char* /*argv*/[])
296303
itemB->origin_y = 0;
297304
localCacheB.put(itemB);
298305
}
306+
item = LVFontGlyphCacheItem::newItem(&localCache, glyphCodes_tofill[i], 10, 10);
307+
if (item)
308+
{
309+
item->origin_x = 0;
310+
item->origin_y = 0;
311+
localCache.put(item);
312+
}
299313
}
300314

301315
printf("size of global cacheA: %u\n", globalCacheA.getSize());
302316
printf("size of global cacheB: %u\n", globalCacheB.getSize());
317+
printf("size of global cache: no data...\n");
303318

304319
// bench lookup based on linked list
305320
printf("bench cache based on linked list...\n");
@@ -319,7 +334,7 @@ int main(int /*argc*/, char* /*argv*/[])
319334
printf("t = %lld\n", tmp);
320335

321336
// bench lookup based on hash table
322-
printf("bench cache based on hash table...\n");
337+
printf("bench cache based on hash table (candidate introduced in cr3.2.32)...\n");
323338
gettimeofday(&ts1, NULL);
324339
for (j = 0; j < bench_sz; j++)
325340
{
@@ -334,9 +349,26 @@ int main(int /*argc*/, char* /*argv*/[])
334349
printf("%lld us\n", elapsed);
335350
printf("t = %lld\n", tmp);
336351

352+
// bench lookup based on hash table
353+
printf("bench cache based on hash table (current version)...\n");
354+
gettimeofday(&ts1, NULL);
355+
for (j = 0; j < bench_sz; j++)
356+
{
357+
for (i = 0; i < lookup_seq_sz; i++)
358+
{
359+
item = localCache.get(lookup_seq[i]);
360+
tmp += item->origin_x;
361+
}
362+
}
363+
gettimeofday(&ts2, NULL);
364+
elapsed = timevalcmp(&ts2, &ts1);
365+
printf("%lld us\n", elapsed);
366+
printf("t = %lld\n", tmp);
367+
337368
// cleanup
338369
globalCacheA.clear();
339370
globalCacheB.clear();
371+
globalCache.clear();
340372
return 0;
341373
}
342374

crengine/src/lvtinydom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11476,8 +11476,8 @@ ldomNode * ldomNode::persist()
1147611476
} else {
1147711477
// TEXT->PTEXT
1147811478
lString8 utf8 = _data._text_ptr->getText();
11479-
delete _data._text_ptr;
1148011479
lUInt32 parentIndex = _data._text_ptr->getParentIndex();
11480+
delete _data._text_ptr;
1148111481
_handle._dataIndex = (_handle._dataIndex & ~0xF) | NT_PTEXT;
1148211482
_data._ptext_addr = getDocument()->_textStorage.allocText(_handle._dataIndex, parentIndex, utf8 );
1148311483
// change type

tinydict/tinydict.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,9 @@ TinyDictZStream::~TinyDictZStream()
604604
if ( unp_buffer )
605605
free( unp_buffer );
606606
if ( chunks )
607-
delete chunks;
607+
delete [] chunks;
608608
if ( offsets )
609-
delete offsets;
609+
delete [] offsets;
610610
}
611611

612612
bool TinyDictZStream::open( FILE * file )

0 commit comments

Comments
 (0)