diff -u af/util/xp/new/orig1/ut_vector.cpp af/util/xp/ut_vector.cpp --- af/util/xp/new/orig1/ut_vector.cpp Wed Oct 01 06:01:53 2003 +++ af/util/xp/ut_vector.cpp Wed Oct 01 05:52:05 2003 @@ -126,21 +126,11 @@ UT_sint32 UT_Vector::addItemSorted(const void* p, int (*compar)(const void *, const void *)) { - if (!m_iCount) return addItem(p); - UT_uint32 i = 0; - int icmp; - - icmp = compar(&p, &m_pEntries[i]); - - while ( icmp > 0 && i < m_iCount - 1) - { - i++; - icmp = compar(&p, &m_pEntries[i]); - } - - return insertItemAt( p, i ); + UT_sint32 slot = binarysearchForSlot(&p, compar); + + return insertItemAt( p, slot ); } UT_sint32 UT_Vector::addItem(const void* p, UT_uint32 * pIndex) @@ -262,6 +252,16 @@ UT_uint32 UT_Vector::binarysearch(void * key, int (*compar)(const void *, const void *)) { + UT_sint32 slot = binarysearchForSlot(key, compar); + + if ((slot == m_iCount) || (0 != (*compar)(key, &m_pEntries[slot]))) + return -1; + else + return slot; +} + +UT_uint32 UT_Vector::binarysearchForSlot(void *key, int (*compar)(const void *, const void *)) +{ UT_sint32 high = m_iCount; UT_sint32 low = -1; UT_sint32 probe; @@ -277,10 +277,7 @@ high = probe; } - if ((high == m_iCount) || (0 != (*compar)(key, &m_pEntries[high]))) - return -1; - else - return high; + return high; } bool UT_Vector::copy(const UT_Vector *pVec) diff -u af/util/xp/new/orig1/ut_vector.h af/util/xp/ut_vector.h --- af/util/xp/new/orig1/ut_vector.h Wed Oct 01 06:02:47 2003 +++ af/util/xp/ut_vector.h Wed Oct 01 04:54:19 2003 @@ -121,6 +121,7 @@ private: UT_sint32 grow(UT_uint32); + UT_uint32 binarysearchForSlot(void *key, int (*compar)(const void *, const void *)); void** m_pEntries; UT_uint32 m_iCount; diff -u text/ptbl/xp/new/orig1/pp_TableAttrProp.cpp text/ptbl/xp/pp_TableAttrProp.cpp --- text/ptbl/xp/new/orig1/pp_TableAttrProp.cpp Wed Oct 01 06:04:59 2003 +++ text/ptbl/xp/pp_TableAttrProp.cpp Wed Oct 01 06:51:12 2003 @@ -88,7 +88,6 @@ pAP->setIndex(u); //$HACK result = (m_vecTableSorted.addItemSorted(pAP,compareAP) == 0); } - // sortTable(); return result; } @@ -104,13 +103,19 @@ delete pNew; return false; } + + pNew->setIndex(u); //$HACK + if (pSubscript) { *pSubscript = u; } - - pNew->setIndex(u); //$HACK - m_vecTableSorted.addItem(pNew, NULL); + else + { + // create default empty AP + pNew->markReadOnly(); + m_vecTableSorted.addItem(pNew, NULL); + } return true; } @@ -130,8 +135,8 @@ pAP->markReadOnly(); - sortTable(); - + m_vecTableSorted.addItemSorted(pAP,compareAP); + *pSubscript = subscript; return true; } @@ -150,12 +155,13 @@ pAP->markReadOnly(); - sortTable(); - + m_vecTableSorted.addItemSorted(pAP,compareAP); + *pSubscript = subscript; return true; } + bool pp_TableAttrProp::findMatch(const PP_AttrProp * pMatch, UT_uint32 * pSubscript) const { @@ -205,9 +211,4 @@ return (const PP_AttrProp *)m_vecTable.getNthItem(subscript); else return NULL; -} - -void pp_TableAttrProp::sortTable(void) -{ - m_vecTableSorted.qsort(compareAP); } diff -u text/ptbl/xp/new/orig1/pp_TableAttrProp.h text/ptbl/xp/pp_TableAttrProp.h --- text/ptbl/xp/new/orig1/pp_TableAttrProp.h Wed Oct 01 06:50:34 2003 +++ text/ptbl/xp/pp_TableAttrProp.h Wed Oct 01 06:50:46 2003 @@ -53,7 +53,6 @@ UT_uint32 * pSubscript) const; const PP_AttrProp * getAP(UT_uint32 subscript) const; - void sortTable(void); protected: UT_Vector m_vecTable; diff -u text/ptbl/xp/new/orig1/pt_VarSet.cpp text/ptbl/xp/pt_VarSet.cpp --- text/ptbl/xp/new/orig1/pt_VarSet.cpp Wed Oct 01 05:59:41 2003 +++ text/ptbl/xp/pt_VarSet.cpp Wed Oct 01 05:59:50 2003 @@ -42,20 +42,10 @@ // create a default A/P as entry zero in each AP table. - PT_AttrPropIndex foo; - - if ( !m_tableAttrProp[0].createAP(&foo) - || !m_tableAttrProp[1].createAP(&foo)) + if ( !m_tableAttrProp[0].createAP(NULL) + || !m_tableAttrProp[1].createAP(NULL)) return false; - ((PP_AttrProp *)getAP(_makeAPIndex(0,0)))->markReadOnly(); - ((PP_AttrProp *)getAP(_makeAPIndex(1,0)))->markReadOnly(); - //$TODO Are the two following calls really needed or just for - // consistency. If these are the first elements in the - // tables, then the tables are already sorted. - m_tableAttrProp[0].sortTable(); - m_tableAttrProp[1].sortTable(); - m_bInitialized = true; return true; }