Bug Tracker

Changeset 2818

Show
Ignore:
Timestamp:
08/21/07 05:43:44 (1 year ago)
Author:
jeresig
Message:

Fix for a selector speed regression (calling a simple selector many times resulted in a significant speed down). This has been fixed by breaking the RegExps? out into the global scope. This required that a closure be implemented around the full jQuery script (which is now the case). Some simple changes were made in addition to the RegExp? one, allowing for some greater flexibility on our part - and hopefully better compression.

Speed results:
http://dev.jquery.com/~john/ticket/1351/ vs.
http://dev.jquery.com/~john/ticket/1351/113.html vs.
http://dev.jquery.com/~john/ticket/1351/112.html

Location:
trunk/jquery/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/event/event.js

    r2791 r2818  
    579579}); 
    580580 
    581 new function(){ 
    582  
    583581    /** 
    584582     * Bind a function to the scroll event of each matched element. 
     
    977975    // A fallback to window.onload, that will always work 
    978976    jQuery.event.add( window, "load", jQuery.ready ); 
    979      
    980 }; 
  • trunk/jquery/src/intro.js

    r1928 r2818  
    11// prevent execution of jQuery if included more than once 
    2 if(typeof window.jQuery == "undefined") { 
     2if(typeof window.jQuery == "undefined") (function(){ 
  • trunk/jquery/src/jquery/jquery.js

    r2817 r2818  
    99 * $Rev$ 
    1010 */ 
    11  
    12 // Global undefined variable 
    13 window.undefined = window.undefined; 
    1411 
    1512/** 
     
    2320 * @cat Core 
    2421 */ 
    25 var jQuery = function(a,c) { 
     22window.jQuery = function(a,c) { 
    2623    // If the context is global, return a new object 
    2724    if ( window == this || !this.init ) 
     
    3633     
    3734// Map the jQuery namespace to the '$' one 
    38 var $ = jQuery; 
     35window.$ = jQuery; 
    3936 
    4037/** 
     
    15281525         
    15291526        if (prop.match(/float/i)) 
    1530             prop = jQuery.styleFloat; 
     1527            prop = styleFloat; 
    15311528 
    15321529        if (!force && elem.style[prop]) 
     
    19411938 * @cat JavaScript 
    19421939 */ 
    1943 new function() { 
    1944     var b = navigator.userAgent.toLowerCase(); 
    1945  
    1946     // Figure out what browser is being used 
    1947     jQuery.browser = { 
    1948         version: (b.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1], 
    1949         safari: /webkit/.test(b), 
    1950         opera: /opera/.test(b), 
    1951         msie: /msie/.test(b) && !/opera/.test(b), 
    1952         mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b) 
    1953     }; 
    1954  
     1940var userAgent = navigator.userAgent.toLowerCase(); 
     1941 
     1942// Figure out what browser is being used 
     1943jQuery.browser = { 
     1944    version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1], 
     1945    safari: /webkit/.test(userAgent), 
     1946    opera: /opera/.test(userAgent), 
     1947    msie: /msie/.test(userAgent) && !/opera/.test(userAgent), 
     1948    mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent) 
     1949}; 
     1950 
     1951var styleFloat = jQuery.browser.msie ? "styleFloat" : "cssFloat"; 
     1952     
     1953jQuery.extend({ 
    19551954    // Check to see if the W3C box model is being used 
    1956     jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat"; 
    1957  
    1958     jQuery.styleFloat = jQuery.browser.msie ? "styleFloat" : "cssFloat"; 
    1959  
    1960     jQuery.props = { 
     1955    boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat", 
     1956     
     1957    styleFloat: jQuery.browser.msie ? "styleFloat" : "cssFloat", 
     1958     
     1959    props: { 
    19611960        "for": "htmlFor", 
    19621961        "class": "className", 
    1963         "float": jQuery.styleFloat, 
    1964         cssFloat: jQuery.styleFloat, 
    1965         styleFloat: jQuery.styleFloat, 
     1962        "float": styleFloat, 
     1963        cssFloat: styleFloat, 
     1964        styleFloat: styleFloat, 
    19661965        innerHTML: "innerHTML", 
    19671966        className: "className", 
     
    19721971        selected: "selected", 
    19731972        maxlength: "maxLength" 
    1974     }; 
    1975  
    1976 }; 
     1973    } 
     1974}); 
    19771975 
    19781976/** 
  • trunk/jquery/src/outro.js

    r1023 r2818  
    1 } 
     1})(); 
  • trunk/jquery/src/selector/selector.js

    r2518 r2818  
     1 
     2var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ? 
     3        "(?:[\\w*_-]|\\\\.)" : 
     4        "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)", 
     5    quickChild = new RegExp("^[/>]\\s*(" + chars + "+)"), 
     6    quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"), 
     7    quickClass = new RegExp("^([#.]?)(" + chars + "*)"); 
     8 
    19jQuery.extend({ 
    210    expr: { 
     
    6371 
    6472        // Match: :even, :last-chlid, #id, .class 
    65         new RegExp("^([:.#]*)(" +  
    66             ( jQuery.chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ? "(?:[\\w*_-]|\\\\.)" : "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)" ) + "+)") 
     73        new RegExp("^([:.#]*)(" + chars + "+)") 
    6774    ], 
    6875 
     
    126133            // An attempt at speeding up child selectors that 
    127134            // point to a specific element tag 
    128             var re = new RegExp("^[/>]\\s*(" + jQuery.chars + "+)"); 
     135            var re = quickChild; 
    129136            var m = re.exec(t); 
    130137 
     
    195202                } else { 
    196203                    // Optimize for the case nodeName#idName 
    197                     var re2 = new RegExp("^(" + jQuery.chars + "+)(#)(" + jQuery.chars + "+)"); 
     204                    var re2 = quickID; 
    198205                    var m = re2.exec(t); 
    199206                     
     
    205212                        // Otherwise, do a traditional filter check for 
    206213                        // ID, class, and element selectors 
    207                         re2 = new RegExp("^([#.]?)(" + jQuery.chars + "*)"); 
     214                        re2 = quickClass; 
    208215                        m = re2.exec(t); 
    209216                    }