public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Use frozen constants on the hot path where possible.
Sun Oct 12 07:45:11 -0700 2008
commit  afa48c563f5faf06227e1b6b1b73f7638cfe960c
tree    28f0f4cac058b9c3f610d0b9042c2d3ae786ecc0
parent  173c4a1889afe4fa355cd768b0c8c66ebbe987f6
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
2
3
4
...
41
42
43
 
 
 
 
 
44
45
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
54
55
56
57
58
59
60
61
62
63
0
@@ -1,4 +1,17 @@
0
 # Most of this list is simply constants frozen for efficiency
0
+# and lowered memory consumption. Every time Ruby VM comes
0
+# across a string or a number or a regexp literal,
0
+# new object is created.
0
+#
0
+# This means if you refer to the same string 6 times per request
0
+# and your application takes 100 requests per second, there are
0
+# 600 objects for weak MRI garbage collector to work on.
0
+#
0
+# GC cycles take up to 80% (!) time of request processing in
0
+# some cases. Eventually Rubinius and maybe MRI 2.0 gonna
0
+# improve this situation but at the moment, all commonly used
0
+# strings, regexp and numbers used as constants so no extra
0
+# objects created and VM just operate pointers.
0
 module Merb
0
     module Const
0
     
0
@@ -41,5 +54,10 @@ module Merb
0
     REQUEST_URI              = "REQUEST_URI".freeze
0
     REQUEST_PATH             = "REQUEST_PATH".freeze
0
     REMOTE_ADDR              = "REMOTE_ADDR".freeze
0
+    BREAK_TAG                = "<br/>".freeze
0
+    EMPTY_STRING             = "".freeze
0
+    NEWLINE                  = "\n".freeze
0
+    DOUBLE_NEWLINE           = "\n\n".freeze
0
+    LOCATION                 = "Location".freeze
0
   end
0
 end
...
16
17
18
19
 
20
21
 
22
23
24
...
41
42
43
44
 
45
46
47
...
16
17
18
 
19
20
 
21
22
23
24
...
41
42
43
 
44
45
46
47
0
@@ -16,9 +16,9 @@ module Merb
0
         begin
0
           rack_response = ::Merb::Dispatcher.handle(Merb::Request.new(env))
0
         rescue Object => e
0
-          return [500, {Merb::Const::CONTENT_TYPE => "text/html"}, e.message + "<br/>" + e.backtrace.join("<br/>")]
0
+          return [500, {Merb::Const::CONTENT_TYPE => "text/html"}, e.message + Merb::Const::BREAK_TAG + e.backtrace.join(Merb::Const::BREAK_TAG)]
0
         end
0
-        Merb.logger.info "\n\n"
0
+        Merb.logger.info Merb::Const::DOUBLE_NEWLINE
0
         Merb.logger.flush
0
 
0
         # unless controller.headers[Merb::Const::DATE]
0
@@ -41,7 +41,7 @@ module Merb
0
       #
0
       # @api private
0
       def deferred?(env)
0
-        path = env[Merb::Const::PATH_INFO] ? env[Merb::Const::PATH_INFO].chomp('/') : ""
0
+        path = env[Merb::Const::PATH_INFO] ? env[Merb::Const::PATH_INFO].chomp(Merb::Const::SLASH) : Merb::Const::EMPTY_STRING
0
         if path =~ Merb.deferred_actions
0
           Merb.logger.info! "Deferring Request: #{path}"
0
           true
...
24
25
26
27
 
28
29
30
31
32
33
34
 
...
24
25
26
 
27
28
29
30
31
32
 
33
34
0
@@ -24,10 +24,10 @@ module Merb
0
         Merb.logger.info("Dispatcher redirecting to: #{url} (#{status})")
0
         Merb.logger.flush
0
         
0
-        [status, { "Location" => url },
0
+        [status, { Merb::Const::LOCATION => url },
0
          Merb::Rack::StreamWrapper.new("<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>")]
0
       end
0
       
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+end

Comments