Use reference instead of primitive

This commit is contained in:
Leeingnyo 2021-09-14 23:07:47 +09:00
parent 670cf54957
commit 9489d6abfd
3 changed files with 19 additions and 12 deletions

View File

@ -143,10 +143,10 @@ class Library
storage = Storage.new auto_close: false
examine_context : ExamineContext = {
file_count: 0,
file_counter: (YieldCounter.new 1000),
cached_contents_signature: {} of String => String,
deleted_title_ids: [] of String,
deleted_entry_ids: [] of String
deleted_title_ids: [] of String,
deleted_entry_ids: [] of String,
}
@title_ids.select! do |title_id|

View File

@ -115,7 +115,7 @@ class Title
previous_entries_size = @entries.size
@entries.select! do |entry|
existence = File.exists? entry.zip_path
yield_process_file context
context["file_counter"].count_and_yield
context["deleted_entry_ids"] << entry.id unless existence
existence
end

View File

@ -134,14 +134,21 @@ class TitleInfo
end
end
class YieldCounter
setter threshold : Int32
def initialize(@threshold : Int32)
@file_count = 0
end
def count_and_yield
@file_count += 1
Fiber.yield if @file_count % @threshold == 0
end
end
alias ExamineContext = NamedTuple(
file_count: Int32,
file_counter: YieldCounter,
cached_contents_signature: Hash(String, String),
deleted_title_ids: Array(String),
deleted_entry_ids: Array(String)
)
def yield_process_file(context : ExamineContext)
context["file_count"] += 1
Fiber.yield if context["file_count"] % 1000 == 0
end
deleted_entry_ids: Array(String))