         str = @pattern
         i = 0
         
-        while @firstParam.test(str)
+        while @RegExpCache.firstParam.test(str)
             # Get the right replacement
             if values[i]?
                 value = if $.isFunction(values[i]) then values[i]() else String(values[i])
             else
                 value = ''
             
-            str = str.replace(@firstParam, value)
+            str = str.replace(@RegExpCache.firstParam, value)
             i++
         
         str

                # Do some escaping and replace the parameter placeholders
                # with the proper regular expression
                pattern = String(pattern)
                pattern = pattern.replace(@escapeRegExp, '\\$&')
                pattern = pattern.replace(@namedParam, '([^\/]+)')
                pattern = pattern.replace(@splatParam, '(.*?)')
                
                @expr = new RegExp('^' + pattern + '$')
            else

class Route
    
    # Cache some static regular expressions - thanks Backbone.js!
    RegExpCache:
        escapeRegExp: /[-[\]{}()+?.,\\^$|#\s]/g
        namedParam: /:\w+/g
        splatParam: /\*\w*/g
        firstParam: /(:\w+)|(\*\w*)/
    
    constructor: (@pattern) ->
        if pattern instanceof RegExp
