String#startsWith, String#endsWith performance optimization [#808 state:resolved]

This commit is contained in:
Juriy Zaytsev 2009-09-28 19:21:37 -04:00
parent f4ea4c6ef7
commit 3b525f194d
2 changed files with 6 additions and 2 deletions

View File

@ -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)

View File

@ -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;
}
/**