Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
c72371f7
Commit
c72371f7
authored
Apr 05, 2011
by
Dan Heberden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve speed of $.map with object support (-5% previous speed) and improve .length detection
parent
00dd6013
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
12 deletions
+11
-12
core.js
src/core.js
+7
-8
sizzle
src/sizzle
+1
-1
qunit
test/qunit
+1
-1
core.js
test/unit/core.js
+2
-2
No files found.
src/core.js
View file @
c72371f7
...
@@ -704,16 +704,15 @@ jQuery.extend({
...
@@ -704,16 +704,15 @@ jQuery.extend({
return
ret
;
return
ret
;
},
},
// arg is for internal usage only
// arg is for internal usage only
map
:
function
(
elems
,
callback
,
arg
)
{
map
:
function
(
elems
,
callback
,
arg
)
{
var
value
,
ret
=
[],
var
value
,
ret
=
[],
i
=
0
,
i
=
0
,
length
=
elems
.
length
,
length
=
elems
.
length
,
//
process .length if it's just an object member
//
jquery objects are treated as arrays
isArray
=
length
!==
undefined
&&
(
elems
[
length
-
1
]
||
jQuery
.
isArray
(
elems
)
)
;
isArray
=
elems
instanceof
jQuery
||
length
!==
undefined
&&
typeof
length
===
"number"
&&
(
(
length
>
0
&&
elems
[
0
]
&&
elems
[
length
-
1
]
)
||
jQuery
.
isArray
(
elems
)
)
;
// Go through the array, translating each of the items to their
// Go through the array, translating each of the items to their
// new value (or values).
if
(
isArray
)
{
if
(
isArray
)
{
for
(
;
i
<
length
;
i
++
)
{
for
(
;
i
<
length
;
i
++
)
{
value
=
callback
(
elems
[
i
],
i
,
arg
);
value
=
callback
(
elems
[
i
],
i
,
arg
);
...
@@ -723,8 +722,8 @@ jQuery.extend({
...
@@ -723,8 +722,8 @@ jQuery.extend({
}
}
}
}
// Go thorugh every key on the object,
// Go thorugh every key on the object,
}
else
{
}
else
{
for
(
key
in
elems
)
{
for
(
key
in
elems
)
{
value
=
callback
(
elems
[
key
],
key
,
arg
);
value
=
callback
(
elems
[
key
],
key
,
arg
);
...
...
sizzle
@
f12b9309
Subproject commit
ef19279f54ba49242c6461d47577c703f4f4e80e
Subproject commit
f12b9309269ba7e705a99efe099f86ed1fe98d58
qunit
@
d404faf8
Subproject commit
cc8460c7b44f023c4f84ab1810b72bf6c6ee4542
Subproject commit
d404faf8f587fcbe6b8907943022e6318dd51e0c
test/unit/core.js
View file @
c72371f7
...
@@ -625,7 +625,7 @@ test("map()", function() {
...
@@ -625,7 +625,7 @@ test("map()", function() {
q
(
"ap"
,
"ap"
,
"ap"
),
q
(
"ap"
,
"ap"
,
"ap"
),
"Single Map"
"Single Map"
);
);
//for #2616
//for #2616
var
keys
=
jQuery
.
map
(
{
a
:
1
,
b
:
2
},
function
(
v
,
k
){
var
keys
=
jQuery
.
map
(
{
a
:
1
,
b
:
2
},
function
(
v
,
k
){
return
k
;
return
k
;
...
@@ -636,7 +636,7 @@ test("map()", function() {
...
@@ -636,7 +636,7 @@ test("map()", function() {
return
v
;
return
v
;
});
});
equals
(
values
.
join
(
""
),
"12"
,
"Map the values from a hash to an array"
);
equals
(
values
.
join
(
""
),
"12"
,
"Map the values from a hash to an array"
);
// object with length prop
// object with length prop
var
values
=
jQuery
.
map
(
{
a
:
1
,
b
:
2
,
length
:
3
},
function
(
v
,
k
){
var
values
=
jQuery
.
map
(
{
a
:
1
,
b
:
2
,
length
:
3
},
function
(
v
,
k
){
return
v
;
return
v
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment