mirror of
https://github.com/koreader/koreader
synced 2024-11-13 19:11:25 +00:00
21b067792d
Ought to be faster than our naive array-based approach. Especially for the glyph cache, which has a solid amount of elements, and is mostly cache hits. (There are few things worse for performance in Lua than table.remove @ !tail and table.insert @ !tail, which this was full of :/). DocCache: New module that's now an actual Cache instance instead of a weird hack. Replaces "Cache" (the instance) as used across Document & co. Only Cache instance with on-disk persistence. ImageCache: Update to new Cache. GlyphCache: Update to new Cache. Also, actually free glyph bbs on eviction.
54 lines
1.6 KiB
Lua
54 lines
1.6 KiB
Lua
describe("Cache module", function()
|
|
local DocumentRegistry, DocCache
|
|
local doc
|
|
local max_page = 1
|
|
setup(function()
|
|
require("commonrequire")
|
|
DocumentRegistry = require("document/documentregistry")
|
|
DocCache = require("document/doccache")
|
|
|
|
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
|
doc = DocumentRegistry:openDocument(sample_pdf)
|
|
end)
|
|
teardown(function()
|
|
doc:close()
|
|
end)
|
|
|
|
it("should clear cache", function()
|
|
DocCache:clear()
|
|
end)
|
|
|
|
it("should serialize blitbuffer", function()
|
|
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
|
|
doc:renderPage(pageno, nil, 1, 0, 1.0, 0)
|
|
DocCache:serialize()
|
|
end
|
|
DocCache:clear()
|
|
end)
|
|
|
|
it("should deserialize blitbuffer", function()
|
|
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
|
|
doc:hintPage(pageno, 1, 0, 1.0, 0)
|
|
end
|
|
DocCache:clear()
|
|
end)
|
|
|
|
it("should serialize koptcontext", function()
|
|
doc.configurable.text_wrap = 1
|
|
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
|
|
doc:renderPage(pageno, nil, 1, 0, 1.0, 0)
|
|
doc:getPageDimensions(pageno)
|
|
DocCache:serialize()
|
|
end
|
|
DocCache:clear()
|
|
doc.configurable.text_wrap = 0
|
|
end)
|
|
|
|
it("should deserialize koptcontext", function()
|
|
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
|
|
doc:renderPage(pageno, nil, 1, 0, 1.0, 0)
|
|
end
|
|
DocCache:clear()
|
|
end)
|
|
end)
|