Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39dae7f

Browse files
committed
Deprecated: optimize regular expression for $.trim for long sequences of whitespace runs
Regex imp implementation takes O(N^2) time to trim the string when multipleadjacent spaces were present.The new expression require that the "whitespace run" starts from a non-whitespaceto avoid O(N^2) behavior when the engine would try matching "\s$" at each space position.
1 parent410d5cf commit39dae7f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

‎src/deprecated.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ define( [
1515

1616
// Support: Android <=4.0 only
1717
// Make sure we trim BOM and NBSP
18-
varrtrim=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
18+
// Require that the "whitespace run" starts from a non-whitespace
19+
// to avoid O(N^2) behavior when the engine would try matching "\s$" at each space position.
20+
varrtrim=/^[\s\uFEFF\xA0]+|([^\s\uFEFF\xA0])[\s\uFEFF\xA0]+$/g;
1921

2022
// Bind a function to a context, optionally partially applying any
2123
// arguments.
@@ -82,6 +84,6 @@ jQuery.isNumeric = function( obj ) {
8284
jQuery.trim=function(text){
8385
returntext==null ?
8486
"" :
85-
(text+"").replace(rtrim,"");
87+
(text+"").replace(rtrim,"$1");
8688
};
8789
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp