perf(tags parser): improuve parser perf
This commit is contained in:
parent
d82620d1ff
commit
626b28ca16
2 changed files with 6 additions and 25 deletions
|
@ -41,11 +41,11 @@ module TagsSubstitutionConcern
|
||||||
end
|
end
|
||||||
|
|
||||||
define_combinator :tag_text_first_char do
|
define_combinator :tag_text_first_char do
|
||||||
any_char.that_fail(lit('-') | tag_delimiter | eol)
|
any_char.that_fail(lit('-') | tag_delimiter)
|
||||||
end
|
end
|
||||||
|
|
||||||
define_combinator :tag_text_char do
|
define_combinator :tag_text_char do
|
||||||
any_char.that_fail(tag_delimiter | eol)
|
any_char.that_fail(tag_delimiter)
|
||||||
end
|
end
|
||||||
|
|
||||||
define_combinator :tag_text do
|
define_combinator :tag_text do
|
||||||
|
@ -53,10 +53,6 @@ module TagsSubstitutionConcern
|
||||||
str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ')
|
str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
define_combinator :eol do
|
|
||||||
lit("\r\n") | lit("\n")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
DOSSIER_TAGS = [
|
DOSSIER_TAGS = [
|
||||||
|
|
|
@ -32,25 +32,10 @@ namespace :benchmarks do
|
||||||
|
|
||||||
desc 'Attestation Template parser'
|
desc 'Attestation Template parser'
|
||||||
task attestation_template_parser: :environment do
|
task attestation_template_parser: :environment do
|
||||||
progress = ProgressReport.new(AttestationTemplate.count)
|
procedure = Procedure.find(68139)
|
||||||
AttestationTemplate.find_each do |template|
|
Benchmark.bm do |x|
|
||||||
parsed = TagsSubstitutionConcern::TagsParser.parse(template.body)
|
x.report("Empty") { TagsSubstitutionConcern::TagsParser.parse('') }
|
||||||
serialized = parsed.map do |token|
|
x.report("Démarche 68139") { TagsSubstitutionConcern::TagsParser.parse(procedure.attestation_template.body) }
|
||||||
case token
|
|
||||||
in { tag: tag }
|
|
||||||
"--#{tag}--"
|
|
||||||
in { text: text }
|
|
||||||
text
|
|
||||||
end
|
|
||||||
end.join('')
|
|
||||||
if serialized != template.body
|
|
||||||
throw "Template '#{serialized}' is not eq '#{template.body}' with attestation template #{template.id}"
|
|
||||||
end
|
|
||||||
progress.inc
|
|
||||||
rescue => e
|
|
||||||
pp "Error with attestation template #{template.id}"
|
|
||||||
throw e
|
|
||||||
end
|
end
|
||||||
progress.finish
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue