Skip to content
This repository

Headers parsing performance optimization #366

Merged
merged 1 commit into from over 1 year ago

2 participants

Bogdan Gusiev Mikel Lindsaar
Bogdan Gusiev

Among other tiny changes this PR contains the following optimization:

-        selected = select_field_for(field.name)
-
-        if selected.any? && limited_field?(field.name) 
+        if limited_field?(field.name) && (selected = select_field_for(field.name)) && selected.any?

This allows select_field_for(that is pretty slow when number of headers is high) be called only when limited_field? returns true.

About 30% performance improvement for Mail::Header.new method when there are a lot of unknown headers.

Mikel Lindsaar
Owner

Nice, thanks :)

Mikel Lindsaar mikel merged commit bced96d into from November 17, 2012
Mikel Lindsaar mikel closed this November 17, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 06, 2012
Bogdan Gusiev Headers parsing performance optimization bced96d
This page is out of date. Refresh to see the latest.
2  lib/mail/fields/common/common_field.rb
@@ -34,7 +34,7 @@ def field_length
34 34
     end
35 35
 
36 36
     def responsible_for?( val )
37  
-      name.to_s.downcase == val.to_s.downcase
  37
+      name.to_s.casecmp(val.to_s) == 0
38 38
     end
39 39
 
40 40
     private
6  lib/mail/header.rb
@@ -78,9 +78,7 @@ def fields=(unfolded_fields)
78 78
 
79 79
         field = Field.new(field, nil, charset)
80 80
         field.errors.each { |error| self.errors << error }
81  
-        selected = select_field_for(field.name)
82  
-
83  
-        if selected.any? && limited_field?(field.name)
  81
+        if limited_field?(field.name) && (selected = select_field_for(field.name)) && selected.any? 
84 82
           selected.first.update(field.name, field.value)
85 83
         else
86 84
           @fields << field
@@ -254,7 +252,7 @@ def split_header
254 252
     end
255 253
     
256 254
     def select_field_for(name)
257  
-      fields.select { |f| f.responsible_for?(name.to_s) }
  255
+      fields.select { |f| f.responsible_for?(name) }
258 256
     end
259 257
     
260 258
     def limited_field?(name)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.