mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Merge pull request #408 from griffpatch/optimisation/avoid-negative-index-lookups
Optimisation - Avoid negative index lookups #407
This commit is contained in:
commit
c2a488a197
1 changed files with 4 additions and 4 deletions
|
@ -101,7 +101,7 @@ Thread.prototype.pushStack = function (blockId) {
|
||||||
if (this.stack.length > this.stackFrames.length) {
|
if (this.stack.length > this.stackFrames.length) {
|
||||||
// Copy warp mode from any higher level.
|
// Copy warp mode from any higher level.
|
||||||
var warpMode = false;
|
var warpMode = false;
|
||||||
if (this.stackFrames[this.stackFrames.length - 1]) {
|
if (this.stackFrames.length > 0 && this.stackFrames[this.stackFrames.length - 1]) {
|
||||||
warpMode = this.stackFrames[this.stackFrames.length - 1].warpMode;
|
warpMode = this.stackFrames[this.stackFrames.length - 1].warpMode;
|
||||||
}
|
}
|
||||||
this.stackFrames.push({
|
this.stackFrames.push({
|
||||||
|
@ -145,7 +145,7 @@ Thread.prototype.popStack = function () {
|
||||||
* @return {?string} Block ID on top of stack.
|
* @return {?string} Block ID on top of stack.
|
||||||
*/
|
*/
|
||||||
Thread.prototype.peekStack = function () {
|
Thread.prototype.peekStack = function () {
|
||||||
return this.stack[this.stack.length - 1];
|
return this.stack.length > 0 ? this.stack[this.stack.length - 1] : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ Thread.prototype.peekStack = function () {
|
||||||
* @return {?Object} Last stack frame stored on this thread.
|
* @return {?Object} Last stack frame stored on this thread.
|
||||||
*/
|
*/
|
||||||
Thread.prototype.peekStackFrame = function () {
|
Thread.prototype.peekStackFrame = function () {
|
||||||
return this.stackFrames[this.stackFrames.length - 1];
|
return this.stackFrames.length > 0 ? this.stackFrames[this.stackFrames.length - 1] : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,7 +162,7 @@ Thread.prototype.peekStackFrame = function () {
|
||||||
* @return {?Object} Second to last stack frame stored on this thread.
|
* @return {?Object} Second to last stack frame stored on this thread.
|
||||||
*/
|
*/
|
||||||
Thread.prototype.peekParentStackFrame = function () {
|
Thread.prototype.peekParentStackFrame = function () {
|
||||||
return this.stackFrames[this.stackFrames.length - 2];
|
return this.stackFrames.length > 1 ? this.stackFrames[this.stackFrames.length - 2] : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue