diff --git a/qwery.js b/qwery.js index 446445b..49e1f46 100644 --- a/qwery.js +++ b/qwery.js @@ -226,15 +226,17 @@ } function uniq(ar) { - var a = [], i, j; - label: - for (i = 0; i < ar.length; i++) { - for (j = 0; j < a.length; j++) { - if (a[j] == ar[i]) continue label; + var r = [], i = 0, j = 0, k, item, inIt + for (; item = ar[i]; ++i) { + inIt = false + for (k = 0; k < r.length; ++k) { + if (r[k] === item) { + inIt = true; break + } } - a[a.length] = ar[i] + if (!inIt) r[j++] = item } - return a + return r } function arrayLike(o) { diff --git a/qwery.min.js b/qwery.min.js index d8c9a2d..4fc7b01 100644 --- a/qwery.min.js +++ b/qwery.min.js @@ -4,4 +4,4 @@ * copyright Dustin Diaz & Jacob Thornton 2011 * MIT License */ -!function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&typeof define.amd=="object"?define(b):this[a]=b()}("qwery",function(){function B(){this.c={}}function G(a){return C.g(a)||C.s(a,new RegExp("(^|\\s+)"+a+"(\\s+|$)"))}function H(a,b){var c=0,d=a.length;for(;c~+]/,p=/^\s+|\s*([,\s\+\~>]|$)\s*/g,q=/[\s\>\+\~]/,r=/(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\]|[\s\w\+\-]*\))/,s=/([.*+?\^=!:${}()|\[\]\/\\])/g,t=/^(\*|[a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/,u=/\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/,v=/:([\w\-]+)(\(['"]?([\s\w\+\-]+)['"]?\))?/,w=new RegExp("("+q.source+")"+r.source,"g"),x=new RegExp(q.source+r.source),y=new RegExp(t.source+"("+u.source+")?"+"("+v.source+")?"),z=/^(([\w\-]*[#\.]?[\w\-]+|\*)?(\[[\w\-]+([\~\|]?=['"][ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+["'])?\])?(\:(link|visited|active|hover))?([\s>+~\.,]|(?:$)))+$/,A={" ":function(a){return a&&a!==d&&a.parentNode},">":function(a,b){return a&&a.parentNode==b.parentNode&&a.parentNode},"~":function(a){return a&&a.previousSibling},"+":function(a,b,c,d){return a?(c=K(a))&&(d=K(b))&&c==d&&c:!1}};B.prototype={g:function(a){return this.c[a]||undefined},s:function(a,b){return this.c[a]=b}};var C=new B,D=new B,E=new B,F=new B,Z="compareDocumentPosition"in d?function(a,b){return(b.compareDocumentPosition(a)&16)==16}:"contains"in d?function(a,b){return b=b.nodeType===9||b==window?d:b,b!==a&&b.contains(a)}:function(a,b){while(a=a.parentNode)if(a===b)return 1;return 0},$=function(){var a=b.createElement("p");return(a.innerHTML='x')&&a.firstChild.getAttribute("href")!="#x"?function(a,b){return b==="class"?a.className:b==="href"||b==="src"?a.getAttribute(b,2):a.getAttribute(b)}:function(a,b){return a.getAttribute(b)}}(),_=function(){if(b[e]&&b.querySelector&&b[g])try{var a=b.createElement("p");return a.innerHTML="",a[g](":nth-of-type(1)").length}catch(c){}return!1}(),ba=function(a,b){var c=[],d,e;try{return b.nodeType===9||!o.test(a)?J(b[g](a)):(H(d=a.split(","),Y(b,function(a,b){e=a[g](b),e.length==1?c[c.length]=e.item(0):e.length&&(c=c.concat(J(e)))})),d.length>1&&c.length>1?T(c):c)}catch(f){}return bc(a,b)},bb=function(a,b){var c,d,e,f,h=[];return a=a.replace(p,"$1"),!o.test(a)&&z.test(a)?J(b[g](a)):(H(f=a.split(","),Y(b,function(a,f,i){d=z.test(f)?a[g](f):P(f,a);for(c=0,e=d.length;c1&&h.length>1?T(h):h)},bc=function(a,b){var c=[],d,e,g,h,i,j;a=a.replace(p,"$1");if(e=a.match(m)){i=G(e[2]),d=b[f](e[1]||"*");for(g=0,h=d.length;g1&&c.length>1?T(c):c},bd=_?ba:b[g]?bb:bc;return X.uniq=T,X.is=Q,X.pseudos={},X.noConflict=function(){return a.qwery=c,this},X}) \ No newline at end of file +!function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&typeof define.amd=="object"?define(b):this[a]=b()}("qwery",function(){function B(){this.c={}}function G(a){return C.g(a)||C.s(a,new RegExp("(^|\\s+)"+a+"(\\s+|$)"))}function H(a,b){var c=0,d=a.length;for(;c~+]/,p=/^\s+|\s*([,\s\+\~>]|$)\s*/g,q=/[\s\>\+\~]/,r=/(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\]|[\s\w\+\-]*\))/,s=/([.*+?\^=!:${}()|\[\]\/\\])/g,t=/^(\*|[a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/,u=/\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/,v=/:([\w\-]+)(\(['"]?([\s\w\+\-]+)['"]?\))?/,w=new RegExp("("+q.source+")"+r.source,"g"),x=new RegExp(q.source+r.source),y=new RegExp(t.source+"("+u.source+")?"+"("+v.source+")?"),z=/^(([\w\-]*[#\.]?[\w\-]+|\*)?(\[[\w\-]+([\~\|]?=['"][ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+["'])?\])?(\:(link|visited|active|hover))?([\s>+~\.,]|(?:$)))+$/,A={" ":function(a){return a&&a!==d&&a.parentNode},">":function(a,b){return a&&a.parentNode==b.parentNode&&a.parentNode},"~":function(a){return a&&a.previousSibling},"+":function(a,b,c,d){return a?(c=K(a))&&(d=K(b))&&c==d&&c:!1}};B.prototype={g:function(a){return this.c[a]||undefined},s:function(a,b){return this.c[a]=b}};var C=new B,D=new B,E=new B,F=new B,Z="compareDocumentPosition"in d?function(a,b){return(b.compareDocumentPosition(a)&16)==16}:"contains"in d?function(a,b){return b=b.nodeType===9||b==window?d:b,b!==a&&b.contains(a)}:function(a,b){while(a=a.parentNode)if(a===b)return 1;return 0},$=function(){var a=b.createElement("p");return(a.innerHTML='x')&&a.firstChild.getAttribute("href")!="#x"?function(a,b){return b==="class"?a.className:b==="href"||b==="src"?a.getAttribute(b,2):a.getAttribute(b)}:function(a,b){return a.getAttribute(b)}}(),_=function(){if(b[e]&&b.querySelector&&b[g])try{var a=b.createElement("p");return a.innerHTML="",a[g](":nth-of-type(1)").length}catch(c){}return!1}(),ba=function(a,b){var c=[],d,e;try{return b.nodeType===9||!o.test(a)?J(b[g](a)):(H(d=a.split(","),Y(b,function(a,b){e=a[g](b),e.length==1?c[c.length]=e.item(0):e.length&&(c=c.concat(J(e)))})),d.length>1&&c.length>1?T(c):c)}catch(f){}return bc(a,b)},bb=function(a,b){var c,d,e,f,h=[];return a=a.replace(p,"$1"),!o.test(a)&&z.test(a)?J(b[g](a)):(H(f=a.split(","),Y(b,function(a,f,i){d=z.test(f)?a[g](f):P(f,a);for(c=0,e=d.length;c1&&h.length>1?T(h):h)},bc=function(a,b){var c=[],d,e,g,h,i,j;a=a.replace(p,"$1");if(e=a.match(m)){i=G(e[2]),d=b[f](e[1]||"*");for(g=0,h=d.length;g1&&c.length>1?T(c):c},bd=_?ba:b[g]?bb:bc;return X.uniq=T,X.is=Q,X.pseudos={},X.noConflict=function(){return a.qwery=c,this},X}) \ No newline at end of file diff --git a/src/qwery.js b/src/qwery.js index 03f0e69..6d38405 100644 --- a/src/qwery.js +++ b/src/qwery.js @@ -219,15 +219,17 @@ } function uniq(ar) { - var a = [], i, j; - label: - for (i = 0; i < ar.length; i++) { - for (j = 0; j < a.length; j++) { - if (a[j] == ar[i]) continue label; + var r = [], i = 0, j = 0, k, item, inIt + for (; item = ar[i]; ++i) { + inIt = false + for (k = 0; k < r.length; ++k) { + if (r[k] === item) { + inIt = true; break + } } - a[a.length] = ar[i] + if (!inIt) r[j++] = item } - return a + return r } function arrayLike(o) { diff --git a/tests/index.html b/tests/index.html index 04fe217..abd8135 100644 --- a/tests/index.html +++ b/tests/index.html @@ -17,7 +17,7 @@ return 'success' } - +