Random nano optimizations (#6801)

* Don't call Screen:afterPaint if nothing was actually painted

* Stupid micro-optimization (os.)time! (pun intended :D)
reviewable/pr6804/r1
NiLuJe 4 years ago committed by GitHub
parent 633d43b322
commit 0406be3319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -927,11 +927,11 @@ function ReaderView:checkAutoSaveSettings()
if not interval then -- no auto save
return
end
if os.time() - self.settings_last_save_ts >= interval*60 then
self.settings_last_save_ts = os.time()
local now_ts = os.time()
if now_ts - self.settings_last_save_ts >= interval*60 then
self.settings_last_save_ts = now_ts
UIManager:nextTick(function()
self.ui:saveSettings()
self.settings_last_save_ts = os.time() -- re-set when saving done
end)
end
end

@ -133,9 +133,10 @@ function BasePowerD:setIntensity(intensity)
end
function BasePowerD:getCapacity()
if os.time() - self.last_capacity_pull_time >= 60 then
local now_ts = os.time()
if now_ts - self.last_capacity_pull_time >= 60 then
self.battCapacity = self:getCapacityHW()
self.last_capacity_pull_time = os.time()
self.last_capacity_pull_time = now_ts
end
return self.battCapacity
end

@ -1132,7 +1132,12 @@ function UIManager:_repaint()
refresh.region.w, refresh.region.h,
refresh.dither)
end
Screen:afterPaint()
-- Don't trigger afterPaint if we did not, in fact, paint anything
if dirty then
Screen:afterPaint()
end
self._refresh_stack = {}
self.refresh_counted = false
end

@ -70,8 +70,9 @@ function AutoSuspend:_schedule()
delay_suspend = self.auto_suspend_sec
delay_shutdown = self.autoshutdown_timeout_seconds
else
delay_suspend = self.last_action_sec + self.auto_suspend_sec - os.time()
delay_shutdown = self.last_action_sec + self.autoshutdown_timeout_seconds - os.time()
local now_ts = os.time()
delay_suspend = self.last_action_sec + self.auto_suspend_sec - now_ts
delay_shutdown = self.last_action_sec + self.autoshutdown_timeout_seconds - now_ts
end
-- Try to shutdown first, as we may have been woken up from suspend just for the sole purpose of doing that.
@ -83,11 +84,11 @@ function AutoSuspend:_schedule()
UIManager:suspend()
else
if self:_enabled() then
logger.dbg("AutoSuspend: schedule suspend at ", os.time() + delay_suspend)
logger.dbg("AutoSuspend: schedule suspend in", delay_suspend)
UIManager:scheduleIn(delay_suspend, self._schedule, self)
end
if self:_enabledShutdown() then
logger.dbg("AutoSuspend: schedule shutdown at ", os.time() + delay_shutdown)
logger.dbg("AutoSuspend: schedule shutdown in", delay_shutdown)
UIManager:scheduleIn(delay_shutdown, self._schedule, self)
end
end
@ -100,8 +101,9 @@ end
function AutoSuspend:_start()
if self:_enabled() or self:_enabledShutdown() then
logger.dbg("AutoSuspend: start at ", os.time())
self.last_action_sec = os.time()
local now_ts = os.time()
logger.dbg("AutoSuspend: start at", now_ts)
self.last_action_sec = now_ts
self:_schedule()
end
end

@ -27,9 +27,9 @@ function AutoTurn:_schedule(settings_id)
return
end
if self.settings_id ~= settings_id then
logger.dbg("AutoTurn:_schedule registered settings_id ",
logger.dbg("AutoTurn:_schedule registered settings_id",
settings_id,
" does not equal to current one ",
"does not equal to current one",
self.settings_id)
return
end
@ -41,10 +41,10 @@ function AutoTurn:_schedule(settings_id)
logger.dbg("AutoTurn: go to next page")
self.ui:handleEvent(Event:new("GotoViewRel", self.autoturn_distance))
end
logger.dbg("AutoTurn: schedule at ", os.time() + self.autoturn_sec)
logger.dbg("AutoTurn: schedule in", self.autoturn_sec)
UIManager:scheduleIn(self.autoturn_sec, function() self:_schedule(settings_id) end)
else
logger.dbg("AutoTurn: schedule at ", os.time() + delay)
logger.dbg("AutoTurn: schedule in", delay)
UIManager:scheduleIn(delay, function() self:_schedule(settings_id) end)
end
end
@ -52,14 +52,15 @@ end
function AutoTurn:_deprecateLastTask()
PluginShare.pause_auto_suspend = false
self.settings_id = self.settings_id + 1
logger.dbg("AutoTurn: deprecateLastTask ", self.settings_id)
logger.dbg("AutoTurn: deprecateLastTask", self.settings_id)
end
function AutoTurn:_start()
if self:_enabled() then
logger.dbg("AutoTurn: start at ", os.time())
local now_ts = os.time()
logger.dbg("AutoTurn: start at", now_ts)
PluginShare.pause_auto_suspend = true
self.last_action_sec = os.time()
self.last_action_sec = now_ts
self:_schedule(self.settings_id)
local text

@ -449,13 +449,14 @@ function CalendarView:init()
outer_padding = math.floor((self.dimen.w - 7*self.day_width - 6*self.inner_padding) / 2)
self.content_width = self.dimen.w - 2*outer_padding
local now_ts = os.time()
if not MIN_MONTH then
local min_ts = self.reader_statistics:getFirstTimestamp()
if not min_ts then min_ts = os.time() end
if not min_ts then min_ts = now_ts end
MIN_MONTH = os.date("%Y-%m", min_ts)
end
self.min_month = MIN_MONTH
self.max_month = os.date("%Y-%m", os.time())
self.max_month = os.date("%Y-%m", now_ts)
if not self.cur_month then
self.cur_month = self.max_month
end

@ -1241,6 +1241,7 @@ function ReaderStatistics:getCurrentStat(id_book)
-- which is computed slightly differently (c.f., insertDB), we'll be using this tweaked book read time
-- to compute the other time-based statistics...
local __, book_read_time = self:getPageTimeTotalStats(id_book)
local now_ts = os.time()
if total_time_book == nil then
total_time_book = 0
@ -1249,14 +1250,14 @@ function ReaderStatistics:getCurrentStat(id_book)
total_read_pages = 0
end
if first_open == nil then
first_open = os.time()
first_open = now_ts
end
self.data.pages = self.view.document:getPageCount()
total_time_book = tonumber(total_time_book)
total_read_pages = tonumber(total_read_pages)
local time_to_read = (self.data.pages - self.view.state.page) * self.avg_time
local estimate_days_to_read = math.ceil(time_to_read/(book_read_time/tonumber(total_days)))
local estimate_end_of_read_date = os.date("%Y-%m-%d", tonumber(os.time() + estimate_days_to_read * 86400))
local estimate_end_of_read_date = os.date("%Y-%m-%d", tonumber(now_ts + estimate_days_to_read * 86400))
local formatstr = "%.0f%%"
return {
-- Global statistics (may consider other books than current book)

Loading…
Cancel
Save