AMTL updates and changes to adapt for them to fix menu crashes (bug 5921, r=psychonic).
AMTL: Removes isVoid from AString. Fixes support inserting to Vector at length. --HG-- extra : rebase_source : 02805fad60c2b759a0e2e91c081144854a8e0b54
This commit is contained in:
parent
fa057e76f3
commit
f0e4fe66ba
@ -636,10 +636,10 @@ bool CBaseMenu::AppendItem(const char *info, const ItemDrawInfo &draw)
|
|||||||
|
|
||||||
item.info = info;
|
item.info = info;
|
||||||
if (draw.display)
|
if (draw.display)
|
||||||
item.display = draw.display;
|
item.display = new ke::AString(draw.display);
|
||||||
item.style = draw.style;
|
item.style = draw.style;
|
||||||
|
|
||||||
m_items.append(item);
|
m_items.append(ke::Move(item));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,10 +657,10 @@ bool CBaseMenu::InsertItem(unsigned int position, const char *info, const ItemDr
|
|||||||
CItem item;
|
CItem item;
|
||||||
item.info = info;
|
item.info = info;
|
||||||
if (draw.display)
|
if (draw.display)
|
||||||
item.display = draw.display;
|
item.display = new ke::AString(draw.display);
|
||||||
item.style = draw.style;
|
item.style = draw.style;
|
||||||
|
|
||||||
m_items.insert(position, item);
|
m_items.insert(position, ke::Move(item));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,7 +685,7 @@ const char *CBaseMenu::GetItemInfo(unsigned int position, ItemDrawInfo *draw/* =
|
|||||||
|
|
||||||
if (draw)
|
if (draw)
|
||||||
{
|
{
|
||||||
draw->display = m_items[position].display.chars();
|
draw->display = m_items[position].display->chars();
|
||||||
draw->style = m_items[position].style;
|
draw->style = m_items[position].style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +45,6 @@ class CItem
|
|||||||
public:
|
public:
|
||||||
CItem()
|
CItem()
|
||||||
{
|
{
|
||||||
info.setVoid();
|
|
||||||
display.setVoid();
|
|
||||||
style = 0;
|
style = 0;
|
||||||
access = 0;
|
access = 0;
|
||||||
}
|
}
|
||||||
@ -57,11 +55,24 @@ public:
|
|||||||
style = other->style;
|
style = other->style;
|
||||||
access = other->access;
|
access = other->access;
|
||||||
}
|
}
|
||||||
|
CItem & operator =(ke::Moveable<CItem> other)
|
||||||
|
{
|
||||||
|
info = ke::Move(other->info);
|
||||||
|
display = ke::Move(other->display);
|
||||||
|
style = other->style;
|
||||||
|
access = other->access;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ke::AString info;
|
ke::AString info;
|
||||||
ke::AString display;
|
ke::AutoPtr<ke::AString> display;
|
||||||
unsigned int style;
|
unsigned int style;
|
||||||
unsigned int access;
|
unsigned int access;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CItem(const CItem &other) KE_DELETE;
|
||||||
|
CItem &operator =(const CItem &other) KE_DELETE;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBaseMenuPlayer
|
class CBaseMenuPlayer
|
||||||
|
@ -204,10 +204,8 @@ HandleType_t HandleSystem::CreateType(const char *name,
|
|||||||
pType->dispatch = dispatch;
|
pType->dispatch = dispatch;
|
||||||
if (name && name[0] != '\0')
|
if (name && name[0] != '\0')
|
||||||
{
|
{
|
||||||
pType->name = name;
|
pType->name = new ke::AString(name);
|
||||||
m_TypeLookup.insert(name, pType);
|
m_TypeLookup.insert(name, pType);
|
||||||
} else {
|
|
||||||
pType->name.setVoid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pType->opened = 0;
|
pType->opened = 0;
|
||||||
@ -924,8 +922,8 @@ bool HandleSystem::RemoveType(HandleType_t type, IdentityToken_t *ident)
|
|||||||
pType->dispatch = NULL;
|
pType->dispatch = NULL;
|
||||||
|
|
||||||
/* Remove it from the type cache. */
|
/* Remove it from the type cache. */
|
||||||
if (!pType->name.isVoid())
|
if (pType->name)
|
||||||
m_TypeLookup.remove(pType->name.chars());
|
m_TypeLookup.remove(pType->name->chars());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1050,8 +1048,8 @@ bool HandleSystem::TryAndFreeSomeHandles()
|
|||||||
continue; /* We may have gaps, it's fine. */
|
continue; /* We may have gaps, it's fine. */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_Types[i].name.isVoid())
|
if (m_Types[i].name)
|
||||||
pTypeName = m_Types[i].name.chars();
|
pTypeName = m_Types[i].name->chars();
|
||||||
else
|
else
|
||||||
pTypeName = "ANON";
|
pTypeName = "ANON";
|
||||||
|
|
||||||
@ -1118,8 +1116,8 @@ void HandleSystem::Dump(HANDLE_REPORTER rep)
|
|||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
unsigned int parentIdx;
|
unsigned int parentIdx;
|
||||||
bool bresult;
|
bool bresult;
|
||||||
if (!pType->name.isVoid())
|
if (pType->name)
|
||||||
type = pType->name.chars();
|
type = pType->name->chars();
|
||||||
|
|
||||||
if ((parentIdx = m_Handles[i].clone) != 0)
|
if ((parentIdx = m_Handles[i].clone) != 0)
|
||||||
{
|
{
|
||||||
|
@ -103,11 +103,11 @@ struct QHandleType
|
|||||||
TypeAccess typeSec;
|
TypeAccess typeSec;
|
||||||
HandleAccess hndlSec;
|
HandleAccess hndlSec;
|
||||||
unsigned int opened;
|
unsigned int opened;
|
||||||
ke::AString name;
|
ke::AutoPtr<ke::AString> name;
|
||||||
|
|
||||||
static inline bool matches(const char *key, const QHandleType *type)
|
static inline bool matches(const char *key, const QHandleType *type)
|
||||||
{
|
{
|
||||||
return type->name.compare(key) == 0;
|
return type->name && type->name->compare(key) == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,29 +104,17 @@ class AString
|
|||||||
return chars()[index];
|
return chars()[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void setVoid() {
|
|
||||||
chars_ = NULL;
|
|
||||||
length_ = kInvalidLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isVoid() const {
|
|
||||||
return length_ == kInvalidLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t length() const {
|
size_t length() const {
|
||||||
assert(!isVoid());
|
|
||||||
return length_;
|
return length_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *chars() const {
|
const char *chars() const {
|
||||||
if (!chars_)
|
if (!chars_)
|
||||||
return isVoid() ? NULL : "";
|
return "";
|
||||||
return chars_;
|
return chars_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const size_t kInvalidLength = (size_t)-1;
|
|
||||||
|
|
||||||
void set(const char *str, size_t length) {
|
void set(const char *str, size_t length) {
|
||||||
chars_ = new char[length + 1];
|
chars_ = new char[length + 1];
|
||||||
length_ = length;
|
length_ = length;
|
||||||
|
@ -91,7 +91,7 @@ class AutoPtr
|
|||||||
: t_(t)
|
: t_(t)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
AutoPtr(Moveable<AutoPtr<T> > &other)
|
AutoPtr(Moveable<AutoPtr<T> > other)
|
||||||
{
|
{
|
||||||
t_ = other->t_;
|
t_ = other->t_;
|
||||||
other->t_ = NULL;
|
other->t_ = NULL;
|
||||||
@ -116,7 +116,7 @@ class AutoPtr
|
|||||||
t_ = t;
|
t_ = t;
|
||||||
return t_;
|
return t_;
|
||||||
}
|
}
|
||||||
T *operator =(Moveable<AutoPtr<T> > &other) {
|
T *operator =(Moveable<AutoPtr<T> > other) {
|
||||||
delete t_;
|
delete t_;
|
||||||
t_ = other->t_;
|
t_ = other->t_;
|
||||||
other->t_ = NULL;
|
other->t_ = NULL;
|
||||||
|
@ -86,14 +86,22 @@ class Vector : public AllocPolicy
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shift all elements including |at| up by one, and insert |item| at the
|
// Shift all elements including |at| up by one, and insert |item| at the
|
||||||
// given position. This is a linear-time operation.
|
// given position. If |at| is one greater than the last usable index,
|
||||||
|
// i.e. |at == length()|, then this is the same as append(). No other
|
||||||
|
// invalid indexes are allowed.
|
||||||
|
//
|
||||||
|
// This is a linear-time operation.
|
||||||
bool insert(size_t at, const T &item) {
|
bool insert(size_t at, const T &item) {
|
||||||
|
if (at == length())
|
||||||
|
return append(item);
|
||||||
if (!moveUp(at))
|
if (!moveUp(at))
|
||||||
return false;
|
return false;
|
||||||
new (&data_[at]) T(item);
|
new (&data_[at]) T(item);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool insert(size_t at, Moveable<T> item) {
|
bool insert(size_t at, Moveable<T> item) {
|
||||||
|
if (at == length())
|
||||||
|
return append(item);
|
||||||
if (!moveUp(at))
|
if (!moveUp(at))
|
||||||
return false;
|
return false;
|
||||||
new (&data_[at]) T(item);
|
new (&data_[at]) T(item);
|
||||||
@ -104,7 +112,7 @@ class Vector : public AllocPolicy
|
|||||||
// element. This is a linear-time operation.
|
// element. This is a linear-time operation.
|
||||||
void remove(size_t at) {
|
void remove(size_t at) {
|
||||||
for (size_t i = at; i < length() - 1; i++)
|
for (size_t i = at; i < length() - 1; i++)
|
||||||
data_[i] = T(Moveable<T>(data_[i + 1]));
|
data_[i] = Moveable<T>(data_[i + 1]);
|
||||||
pop();
|
pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,11 +186,12 @@ class Vector : public AllocPolicy
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool moveUp(size_t at) {
|
bool moveUp(size_t at) {
|
||||||
|
assert(at < nitems_);
|
||||||
if (!growIfNeeded(1))
|
if (!growIfNeeded(1))
|
||||||
return false;
|
return false;
|
||||||
nitems_++;
|
nitems_++;
|
||||||
for (size_t i = nitems_ - 1; i > at; i--)
|
for (size_t i = nitems_ - 1; i > at; i--)
|
||||||
data_[i] = T(Moveable<T>(data_[i - 1]));
|
data_[i] = Moveable<T>(data_[i - 1]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user