Headers parsing performance optimization #366

Merged
merged 1 commit into from Nov 17, 2012
@@ -34,7 +34,7 @@ def field_length
end
def responsible_for?( val )
- name.to_s.downcase == val.to_s.downcase
+ name.to_s.casecmp(val.to_s) == 0
end
private
View
@@ -78,9 +78,7 @@ def fields=(unfolded_fields)
field = Field.new(field, nil, charset)
field.errors.each { |error| self.errors << error }
- 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?
selected.first.update(field.name, field.value)
else
@fields << field
@@ -254,7 +252,7 @@ def split_header
end
def select_field_for(name)
- fields.select { |f| f.responsible_for?(name.to_s) }
+ fields.select { |f| f.responsible_for?(name) }
end
def limited_field?(name)