Loading...
--- xnu/xnu-3789.31.2/libkern/c++/OSSerialize.cpp
+++ xnu/xnu-3248.30.4/libkern/c++/OSSerialize.cpp
@@ -70,40 +70,42 @@
bzero((void *)data, capacity);
length = 1;
}
+ tag = 0;
tags->flushCollection();
}
bool OSSerialize::previouslySerialized(const OSMetaClassBase *o)
{
char temp[16];
- unsigned int tagIdx;
+ OSString *tagString;
if (binary) return (binarySerialize(o));
// look it up
- tagIdx = tags->getNextIndexOfObject(o, 0);
+ tagString = (OSString *)tags->getObject((const OSSymbol *) o);
// xx-review: no error checking here for addString calls!
// does it exist?
- if (tagIdx != -1U) {
+ if (tagString) {
addString("<reference IDREF=\"");
- snprintf(temp, sizeof(temp), "%u", tagIdx);
- addString(temp);
+ addString(tagString->getCStringNoCopy());
addString("\"/>");
return true;
}
- // add to tag array
- tags->setObject(o);// XXX check return
+ // build a tag
+ snprintf(temp, sizeof(temp), "%u", tag++);
+ tagString = OSString::withCString(temp);
+
+ // add to tag dictionary
+ tags->setObject((const OSSymbol *) o, tagString);// XXX check return
+ tagString->release();
return false;
}
bool OSSerialize::addXMLStartTag(const OSMetaClassBase *o, const char *tagString)
{
- char temp[16];
- unsigned int tagIdx;
-
if (binary)
{
printf("class %s: xml serialize\n", o->getMetaClass()->getClassName());
@@ -113,10 +115,7 @@
if (!addChar('<')) return false;
if (!addString(tagString)) return false;
if (!addString(" ID=\"")) return false;
- tagIdx = tags->getNextIndexOfObject(o, 0);
- assert(tagIdx != -1U);
- snprintf(temp, sizeof(temp), "%u", tagIdx);
- if (!addString(temp))
+ if (!addString(((OSString *)tags->getObject((const OSSymbol *)o))->getCStringNoCopy()))
return false;
if (!addChar('\"')) return false;
if (!addChar('>')) return false;
@@ -165,22 +164,14 @@
if (!super::init())
return false;
- tags = OSArray::withCapacity(256);
+ tags = OSDictionary::withCapacity(32);
if (!tags) {
return false;
}
+ tag = 0;
length = 1;
-
- if (!inCapacity) {
- inCapacity = 1;
- }
- if (round_page_overflow(inCapacity, &capacity)) {
- tags->release();
- tags = 0;
- return false;
- }
-
+ capacity = (inCapacity) ? round_page_32(inCapacity) : round_page_32(1);
capacityIncrement = capacity;
// allocate from the kernel map so that we can safely map this data
@@ -228,9 +219,8 @@
if (newCapacity <= capacity)
return capacity;
- if (round_page_overflow(newCapacity, &newCapacity)) {
- return capacity;
- }
+ // round up
+ newCapacity = round_page_32(newCapacity);
kern_return_t rc = kmem_realloc(kernel_map,
(vm_offset_t)data,