Changeset 7861
- Timestamp:
- 10/13/07 19:05:19 (1 year ago)
- Files:
-
- spinoffs/prototype/trunk/CHANGELOG (modified) (1 diff)
- spinoffs/prototype/trunk/src/string.js (modified) (1 diff)
- spinoffs/prototype/trunk/test/unit/string.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/prototype/trunk/CHANGELOG
r7855 r7861 1 1 *SVN* 2 3 * Performance improvements to String#times. [Martin Ström] 2 4 3 5 * Make Ajax.Response#getHeaderJSON and Ajax.Response#getResponseJSON pseudo private instance methods. [Tobie Langel] spinoffs/prototype/trunk/src/string.js
r7344 r7861 120 120 121 121 times: function(count) { 122 var result = ''; 123 for (var i = 0; i < count; i++) result += this; 124 return result; 122 return count < 1 ? '' : new Array(count + 1).join(this); 125 123 }, 126 124 spinoffs/prototype/trunk/test/unit/string.html
r7221 r7861 464 464 465 465 testTimes: function() {with(this) { 466 466 467 assertEqual('', ''.times(0)); 467 468 assertEqual('', ''.times(5)); 469 assertEqual('', 'a'.times(-1)); 468 470 assertEqual('', 'a'.times(0)); 469 471 assertEqual('a', 'a'.times(1)); 472 assertEqual('aa', 'a'.times(2)); 470 473 assertEqual('aaaaa', 'a'.times(5)); 471 474 assertEqual('foofoofoofoofoo', 'foo'.times(5)); 472 475 assertEqual('', 'foo'.times(-5)); 476 477 /*window.String.prototype.oldTimes = function(count) { 478 var result = ''; 479 for (var i = 0; i < count; i++) result += this; 480 return result; 481 }; 482 483 benchmark(function() { 484 'foo'.times(15); 485 }, 1000, 'new: '); 486 487 benchmark(function() { 488 'foo'.oldTimes(15); 489 }, 1000, 'previous: ');*/ 473 490 }}, 474 491