public
Fork of wycats/merb-core
Description: ivey's experimental merb-core
Homepage: http://gweezlebur.com
Clone URL: git://github.com/ivey/merb-core.git
Search Repo:
Improve speed of content-type=. 5% speed on hello world requests.
wycats (author)
Sat Jun 21 00:00:00 -0700 2008
commit  2a9453adc10081789709d743a31b270731af4c20
tree    438e3dfb5d59447e0ae291e1bbef696722e07cf5
parent  3af4e28937f6b91a02c6d778953255fe9437db9a
...
40
41
42
 
 
 
 
 
 
 
43
44
45
46
 
 
47
48
49
...
40
41
42
43
44
45
46
47
48
49
50
51
52
 
53
54
55
56
57
0
@@ -40,10 +40,18 @@ module Merb
0
     # is set (in the controller's #content_type method)
0
     def add_mime_type(key, transform_method, mimes, new_response_headers = {}, &block)
0
       enforce!(key => Symbol, mimes => Array)
0
+
0
+ content_type = new_response_headers["Content-Type"] || mimes.first
0
+
0
+ if charset = new_response_headers.delete(:charset)
0
+ content_type += "; charset=#{charset}"
0
+ end
0
+
0
       ResponderMixin::TYPES.update(key =>
0
         {:accepts => mimes,
0
          :transform_method => transform_method,
0
- :response_headers => new_response_headers,
0
+ # Use symbol to speed compares later
0
+ :response_headers => new_response_headers.update(:"Content-Type" => content_type),
0
          :response_block => block })
0
 
0
       mimes.each do |mime|
...
362
363
364
365
366
367
368
369
370
371
372
373
374
 
 
 
 
 
375
376
377
378
 
 
 
379
 
380
381
382
 
 
383
384
385
...
362
363
364
 
 
 
 
 
 
 
 
 
 
365
366
367
368
369
370
 
 
 
371
372
373
374
375
376
 
 
377
378
379
380
381
0
@@ -362,24 +362,20 @@ module Merb
0
       unless Merb.available_mime_types.has_key?(type)
0
         raise Merb::ControllerExceptions::NotAcceptable.new("Unknown content_type for response: #{type}")
0
       end
0
- # set the Content-Type header - defaults to first accepted mime
0
- if Merb.available_mime_types[type][:response_headers]['Content-Type']
0
- headers['Content-Type'] = Merb.available_mime_types[type][:response_headers]['Content-Type']
0
- else
0
- headers['Content-Type'] = Merb.available_mime_types[type][:accepts].first
0
- # explicitly append the character set to the Content-Type header
0
- if Merb.available_mime_types[type][:response_headers][:charset]
0
- headers['Content-Type'] += "; charset=#{Merb.available_mime_types[type][:response_headers][:charset]}"
0
- end
0
- end
0
+
0
+ mime = Merb.available_mime_types[type]
0
+
0
+ headers["Content-Type"] = mime[:response_headers][:"Content-Type"]
0
+
0
       # merge any format specific response headers
0
- Merb.available_mime_types[type][:response_headers].each do |key, value|
0
- next if key == :charset || headers.key?(key)
0
- headers[key] = value
0
+ mime[:response_headers].each do |key, value|
0
+ next if key == :"Content-Type"
0
+ headers[key] ||= value
0
       end
0
+
0
       # if given, use a block to finetune any runtime headers
0
- if Merb.available_mime_types[type][:response_block].respond_to?(:call)
0
- Merb.available_mime_types[type][:response_block].call(self)
0
+ if mime[:response_block].respond_to?(:call)
0
+ mime[:response_block].call(self)
0
       end
0
       @_content_type = type
0
     end

Comments

    No one has commented yet.