From 3b525f194d0e573923c7d9ad1cbd0cf63a849954 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Mon, 28 Sep 2009 19:21:37 -0400 Subject: [PATCH] String#startsWith, String#endsWith performance optimization [#808 state:resolved] --- CHANGELOG | 4 ++++ src/lang/string.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f5df87f..8934083 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/src/lang/string.js b/src/lang/string.js index 16935a7..3c7f23f 100644 --- a/src/lang/string.js +++ b/src/lang/string.js @@ -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; } /**