summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
authorViraj Mahesh <virajmahesh@gmail.com>2014-03-12 20:04:16 -0700
committerViraj Mahesh <virajmahesh@gmail.com>2014-03-12 20:04:16 -0700
commitdbb5a8e0f5d2d882120c56da4aec00f4c2b569be (patch)
tree8786621a834c283216cfc0df1f0595938b3cd75d /objects.js
parentfa02caef5d5944496dcd32a677ba38c10a8768d9 (diff)
downloadsnap-byow-dbb5a8e0f5d2d882120c56da4aec00f4c2b569be.tar.gz
snap-byow-dbb5a8e0f5d2d882120c56da4aec00f4c2b569be.zip
Made reg-exp static
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js27
1 files changed, 13 insertions, 14 deletions
diff --git a/objects.js b/objects.js
index 9e103be..91febf2 100644
--- a/objects.js
+++ b/objects.js
@@ -3716,22 +3716,21 @@ SpriteMorph.prototype.newCostumeNameCached = function (data) {
return data;
};
+var re = /\((\d+)\)$/;
SpriteMorph.prototype.newCostumeNameFn = function (name) {
- var costume,
- foundSameName = false,
+ var foundSameName = false,
foundIndex = false,
- lastIndex = 0,
- re;
- for(i = 1; i <= this.costumes.length(); i++) { // Find a costume with the same name
- costume = this.costumes.at(i); // Get the ith costume
- if (costume != undefined) {
- if (costume.name === name) { // Same name exists
+ lastIndex = 0;
+ for (i = 1; i <= this.costumes.length(); i++) {
+ var costume = this.costumes.at(i);
+ if (costume != null) {
+ if (costume.name === name) {
foundSameName = true;
}
- if (foundSameName) { // Scan for indexes
- re = new RegExp(name + '\\(\\d+\\)'); // Reg Exp to check for digits
- if (re.test(costume.name)) { // The costume name matches
- lastIndex = parseInt(costume.name.match(/\d+/)[0]);
+ if (foundSameName) {
+ var p = re.exec(costume.name);
+ if (p) {
+ lastIndex = Number(p[1]);
foundIndex = true;
}
}
@@ -3751,8 +3750,8 @@ SpriteMorph.prototype.doScreenshot = function (imgSource, data) {
var canvas,
stage = this.parentThatIsA(StageMorph),
costume;
- //data = this.newCostumeNameFn(data);
- data = this.newCostumeNameCached(data); // Uncomment to profile
+ data = this.newCostumeNameFn(data);
+ //data = this.newCostumeNameCached(data); // Uncomment to profile
if (imgSource[0] === "pen trails") {
canvas = stage.trailsCanvas;
costume = new Costume(canvas, data).copy(); // Copy is required to prevent mutation