String#startsWith, String#endsWith performance optimization [#808 state:resolved]
This commit is contained in:
parent
f4ea4c6ef7
commit
3b525f194d
@ -1,3 +1,7 @@
|
||||
* String#startsWith, String#endsWith performance optimization (Yaffle, Tobie Langel, kangax)
|
||||
|
||||
* Rewrite String#camelize using String#replace with a replacement function (Phred, John-David Dalton, Samuel Lebeau, kangax)
|
||||
|
||||
*1.6.1* (August 24, 2009)
|
||||
|
||||
* Avoid triggering a warning when Java is disabled in IE8. [#668 state:resolved] (orv, kangax, Andrew Dupont, Tobie Langel)
|
||||
|
@ -429,7 +429,7 @@ Object.extend(String.prototype, (function() {
|
||||
* Checks if the string starts with `substring`.
|
||||
**/
|
||||
function startsWith(pattern) {
|
||||
return this.indexOf(pattern) === 0;
|
||||
return !this.lastIndexOf(pattern,0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -439,7 +439,7 @@ Object.extend(String.prototype, (function() {
|
||||
**/
|
||||
function endsWith(pattern) {
|
||||
var d = this.length - pattern.length;
|
||||
return d >= 0 && this.lastIndexOf(pattern) === d;
|
||||
return d >= 0 && this.indexOf(pattern,d) === d;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user