protected internal void RemoveUnusedNode(PdfObject obj, bool[] hits) {
Stack state = new Stack();
state.Push(obj);
while (state.Count != 0) {
Object current = state.Pop();
if (current == null)
continue;
ArrayList ar = null;
PdfDictionary dic = null;
PdfName[] keys = null;
Object[] objs = null;
int idx = 0;
if (current is PdfObject) {
obj = (PdfObject)current;
switch (obj.Type) {
case PdfObject.DICTIONARY:
case PdfObject.STREAM:
dic = (PdfDictionary)obj;
keys = new PdfName[dic.Size];
dic.Keys.CopyTo(keys, 0);
break;
case PdfObject.ARRAY:
ar = ((PdfArray)obj).ArrayList;
break;
case PdfObject.INDIRECT:
PRIndirectReference refi = (PRIndirectReference)obj;
int num = refi.Number;
if (!hits[num]) {
hits[num] = true;
state.Push(GetPdfObjectRelease(refi));
}
continue;
default:
continue;
}
}
else {
objs = (Object[])current;
if (objs[0] is ArrayList) {
ar = (ArrayList)objs[0];
idx = (int)objs[1];
}
else {
keys = (PdfName[])objs[0];
dic = (PdfDictionary)objs[1];
idx = (int)objs[2];
}
}
if (ar != null) {
for (int k = idx; k < ar.Count; ++k) {
PdfObject v = (PdfObject)ar[k];
if (v.IsIndirect()) {
int num = ((PRIndirectReference)v).Number;
if (num >= xrefObj.Count || (!partial && xrefObj[num] == null)) {
ar[k] = PdfNull.PDFNULL;
continue;
}
}
if (objs == null)
state.Push(new Object[]{ar, k + 1});
else {
objs[1] = k + 1;
state.Push(objs);
}
state.Push(v);
break;
}
}
else {
for (int k = idx; k < keys.Length; ++k) {
PdfName key = keys[k];
PdfObject v = dic.Get(key);
if (v.IsIndirect()) {
int num = ((PRIndirectReference)v).Number;
if (num >= xrefObj.Count || (!partial && xrefObj[num] == null)) {
dic.Put(key, PdfNull.PDFNULL);
continue;
}
}
if (objs == null)
state.Push(new Object[]{keys, dic, k + 1});
else {
objs[2] = k + 1;
state.Push(objs);
}
state.Push(v);
break;
}
}
}
}