Nits to Queue<T>, assert valid index and support 0 starting size (bug 500554, r=gal).

This commit is contained in:
David Anderson 2009-06-25 17:14:54 -07:00
parent 2d9f80b8df
commit cf5bda02f1
2 changed files with 17 additions and 7 deletions

View File

@ -370,7 +370,7 @@ getExitName(ExitType type)
NULL
};
JS_ASSERT(unsigned(type) < TOTAL_EXIT_TYPES);
JS_ASSERT(type < TOTAL_EXIT_TYPES);
return exitNames[type];
}
@ -1540,13 +1540,13 @@ specializeTreesToMissingGlobals(JSContext* cx, JSObject* globalObj, TreeInfo* ro
JS_ASSERT(ti->globalSlots->length() == ti->typeMap.length() - ti->nStackTypes);
for (unsigned i = 0; i < root->dependentTrees.length(); i++) {
ti = (TreeInfo*)root->dependentTrees.data()[i]->vmprivate;
ti = (TreeInfo*)root->dependentTrees[i]->vmprivate;
/* ti can be NULL if we hit the recording tree in emitTreeCall; this is harmless. */
if (ti && ti->nGlobalTypes() < ti->globalSlots->length())
specializeTreesToMissingGlobals(cx, globalObj, ti);
}
for (unsigned i = 0; i < root->linkedTrees.length(); i++) {
ti = (TreeInfo*)root->linkedTrees.data()[i]->vmprivate;
ti = (TreeInfo*)root->linkedTrees[i]->vmprivate;
if (ti && ti->nGlobalTypes() < ti->globalSlots->length())
specializeTreesToMissingGlobals(cx, globalObj, ti);
}
@ -1680,7 +1680,7 @@ TraceRecorder::~TraceRecorder()
js_TrashTree(cx, fragment->root);
for (unsigned int i = 0; i < whichTreesToTrash.length(); i++)
js_TrashTree(cx, whichTreesToTrash.get(i));
js_TrashTree(cx, whichTreesToTrash[i]);
} else if (wasRootFragment) {
delete treeInfo;
}
@ -3700,7 +3700,7 @@ TraceRecorder::joinEdgesToEntry(Fragmento* fragmento, VMFragment* peer_root)
for (unsigned i = 0; i < stackCount; i++)
oracle.markStackSlotUndemotable(cx, stackDemotes[i]);
for (unsigned i = 0; i < globalCount; i++)
oracle.markGlobalSlotUndemotable(cx, ti->globalSlots->data()[globalDemotes[i]]);
oracle.markGlobalSlotUndemotable(cx, ti->globalSlots->get(globalDemotes[i]));
JS_ASSERT(peer == uexit->fragment->root);
if (fragment == peer)
trashSelf = true;

View File

@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sw=4 et tw=99 ft=cpp:
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -62,6 +62,8 @@ class Queue : public avmplus::GCObject {
unsigned _max;
void ensure(unsigned size) {
if (!_max)
_max = 16;
while (_max < size)
_max <<= 1;
_data = (T*)realloc(_data, _max * sizeof(T));
@ -73,7 +75,10 @@ public:
Queue(unsigned max = 16) {
this->_max = max;
this->_len = 0;
this->_data = (T*)malloc(max * sizeof(T));
if (max)
this->_data = (T*)malloc(max * sizeof(T));
else
this->_data = NULL;
}
~Queue() {
@ -116,9 +121,14 @@ public:
}
const T & get(unsigned i) const {
JS_ASSERT(i < length());
return _data[i];
}
const T & operator [](unsigned i) const {
return get(i);
}
unsigned length() const {
return _len;
}