MarkedBlock::FreeList MarkedBlock::specializedSweep() { ASSERT(blockState != Allocated && blockState != FreeListed); ASSERT(destructorCallNeeded || sweepMode != SweepOnly); // This produces a free list that is ordered in reverse through the block. // This is fine, since the allocation code makes no assumptions about the // order of the free list. FreeCell* head = 0; size_t count = 0; for (size_t i = firstAtom(); i < m_endAtom; i += m_atomsPerCell) { if (blockState == Marked && m_marks.get(i)) continue; JSCell* cell = reinterpret_cast_ptr<JSCell*>(&atoms()[i]); if (blockState == Zapped && !cell->isZapped()) continue; if (destructorCallNeeded && blockState != New) callDestructor(cell); if (sweepMode == SweepToFreeList) { FreeCell* freeCell = reinterpret_cast<FreeCell*>(cell); freeCell->next = head; head = freeCell; ++count; } } m_state = ((sweepMode == SweepToFreeList) ? FreeListed : Zapped); return FreeList(head, count * cellSize()); }
MarkedBlock::FreeList MarkedBlock::specializedSweep() { ASSERT(blockState != Allocated && blockState != FreeListed); ASSERT(!(dtorType == MarkedBlock::None && sweepMode == SweepOnly)); // This produces a free list that is ordered in reverse through the block. // This is fine, since the allocation code makes no assumptions about the // order of the free list. FreeCell* head = 0; size_t count = 0; for (size_t i = firstAtom(); i < m_endAtom; i += m_atomsPerCell) { if (blockState == Marked && (m_marks.get(i) || (m_newlyAllocated && m_newlyAllocated->get(i)))) continue; JSCell* cell = reinterpret_cast_ptr<JSCell*>(&atoms()[i]); if (dtorType != MarkedBlock::None && blockState != New) callDestructor(cell); if (sweepMode == SweepToFreeList) { FreeCell* freeCell = reinterpret_cast<FreeCell*>(cell); freeCell->next = head; head = freeCell; ++count; } } // We only want to discard the newlyAllocated bits if we're creating a FreeList, // otherwise we would lose information on what's currently alive. if (sweepMode == SweepToFreeList && m_newlyAllocated) m_newlyAllocated.clear(); m_state = ((sweepMode == SweepToFreeList) ? FreeListed : Marked); return FreeList(head, count * cellSize()); }
QString Text::toString() const { QString str; const Atom *atom = firstAtom(); while ( atom != 0 ) { if ( atom->type() == Atom::String || atom->type() == Atom::AutoLink ) str += atom->string(); atom = atom->next(); } return str; }
void Text::dump() const { const Atom* atom = firstAtom(); while (atom != 0) { QString str = atom->string(); str.replace("\\", "\\\\"); str.replace("\"", "\\\""); str.replace("\n", "\\n"); str.replace(QRegExp("[^\x20-\x7e]"), "?"); if (!str.isEmpty()) str = " \"" + str + "\""; fprintf(stderr, " %-15s%s\n", atom->typeString().toLatin1().data(), str.toLatin1().data()); atom = atom->next(); } }
Text Text::subText( Atom::Type left, Atom::Type right, const Atom *from ) const { const Atom *begin = from ? from : firstAtom(); const Atom *end; while ( begin != 0 && begin->type() != left ) begin = begin->next(); if ( begin != 0 ) begin = begin->next(); end = begin; while ( end != 0 && end->type() != right ) end = end->next(); if ( end == 0 ) begin = 0; return subText( begin, end ); }
Text Text::subText(Atom::Type left, Atom::Type right, const Atom* from, bool inclusive) const { const Atom* begin = from ? from : firstAtom(); const Atom* end; while (begin != 0 && begin->type() != left) begin = begin->next(); if (begin != 0) { if (!inclusive) begin = begin->next(); } end = begin; while (end != 0 && end->type() != right) end = end->next(); if (end == 0) begin = 0; else if (inclusive) end = end->next(); return subText(begin, end); }