Commit effd7e1c authored by mjs's avatar mjs

JavaScriptCore:

	Partway to removing Value from List. Created a marking List
	variant, used it in place of ListImp.

        * kjs/internal.h: Removed List stuff.
        * kjs/internal.cpp:
        (InterpreterImp::mark): Call appropriate List method to do marking of
	empty ListImp.
        * kjs/object.h:
        * kjs/object.cpp: Use marking List instead of ListImp *.
        * kjs/types.h:
        * kjs/types.cpp:
        (List::List): New boolean needsMarking parameter.
        (List::operator=): Perform trickery related to needsMarking.
        (List::~List): Likewise.
        (List::mark): Mark the ListImp.
        (List::markEmptyList):
	(ListImp::*): Moved here fron internal.cpp, they will be
	integrated into the relevant List methods soon.

WebCore:

        * force-js-clean-timestamp: Rebuild for JSC changes.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2741 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2dd6a841
2002-11-18 Maciej Stachowiak <mjs@apple.com>
Partway to removing Value from List. Created a marking List
variant, used it in place of ListImp.
* kjs/internal.h: Removed List stuff.
* kjs/internal.cpp:
(InterpreterImp::mark): Call appropriate List method to do marking of
empty ListImp.
* kjs/object.h:
* kjs/object.cpp: Use marking List instead of ListImp *.
* kjs/types.h:
* kjs/types.cpp:
(List::List): New boolean needsMarking parameter.
(List::operator=): Perform trickery related to needsMarking.
(List::~List): Likewise.
(List::mark): Mark the ListImp.
(List::markEmptyList):
(ListImp::*): Moved here fron internal.cpp, they will be
integrated into the relevant List methods soon.
2002-11-18 Darin Adler <darin@apple.com>
- another string constant discovered that can be optimized
......
2002-11-18 Maciej Stachowiak <mjs@apple.com>
Partway to removing Value from List. Created a marking List
variant, used it in place of ListImp.
* kjs/internal.h: Removed List stuff.
* kjs/internal.cpp:
(InterpreterImp::mark): Call appropriate List method to do marking of
empty ListImp.
* kjs/object.h:
* kjs/object.cpp: Use marking List instead of ListImp *.
* kjs/types.h:
* kjs/types.cpp:
(List::List): New boolean needsMarking parameter.
(List::operator=): Perform trickery related to needsMarking.
(List::~List): Likewise.
(List::mark): Mark the ListImp.
(List::markEmptyList):
(ListImp::*): Moved here fron internal.cpp, they will be
integrated into the relevant List methods soon.
2002-11-18 Darin Adler <darin@apple.com>
- another string constant discovered that can be optimized
......
2002-11-18 Maciej Stachowiak <mjs@apple.com>
Partway to removing Value from List. Created a marking List
variant, used it in place of ListImp.
* kjs/internal.h: Removed List stuff.
* kjs/internal.cpp:
(InterpreterImp::mark): Call appropriate List method to do marking of
empty ListImp.
* kjs/object.h:
* kjs/object.cpp: Use marking List instead of ListImp *.
* kjs/types.h:
* kjs/types.cpp:
(List::List): New boolean needsMarking parameter.
(List::operator=): Perform trickery related to needsMarking.
(List::~List): Likewise.
(List::mark): Mark the ListImp.
(List::markEmptyList):
(ListImp::*): Moved here fron internal.cpp, they will be
integrated into the relevant List methods soon.
2002-11-18 Darin Adler <darin@apple.com>
- another string constant discovered that can be optimized
......
......@@ -331,216 +331,6 @@ void LabelStack::clear()
}
}
// ------------------------------ ListImp --------------------------------------
#ifdef KJS_DEBUG_MEM
int ListImp::count = 0;
#endif
Value ListImp::toPrimitive(ExecState */*exec*/, Type /*preferredType*/) const
{
// invalid for List
assert(false);
return Value();
}
bool ListImp::toBoolean(ExecState */*exec*/) const
{
// invalid for List
assert(false);
return false;
}
double ListImp::toNumber(ExecState */*exec*/) const
{
// invalid for List
assert(false);
return 0;
}
UString ListImp::toString(ExecState */*exec*/) const
{
// invalid for List
assert(false);
return UString::null;
}
Object ListImp::toObject(ExecState */*exec*/) const
{
// invalid for List
assert(false);
return Object();
}
ListImp::ListImp()
{
#ifdef KJS_DEBUG_MEM
count++;
#endif
hook = new ListNode(Null(), 0L, 0L);
hook->next = hook;
hook->prev = hook;
//fprintf(stderr,"ListImp::ListImp %p hook=%p\n",this,hook);
}
ListImp::~ListImp()
{
//fprintf(stderr,"ListImp::~ListImp %p\n",this);
#ifdef KJS_DEBUG_MEM
count--;
#endif
clear();
delete hook;
if ( emptyList == this )
emptyList = 0L;
}
void ListImp::mark()
{
ListNode *n = hook->next;
while (n != hook) {
if (!n->member->marked())
n->member->mark();
n = n->next;
}
ValueImp::mark();
}
void ListImp::append(const Value& obj)
{
ListNode *n = new ListNode(obj, hook->prev, hook);
hook->prev->next = n;
hook->prev = n;
}
void ListImp::prepend(const Value& obj)
{
ListNode *n = new ListNode(obj, hook, hook->next);
hook->next->prev = n;
hook->next = n;
}
void ListImp::appendList(const List& lst)
{
ListIterator it = lst.begin();
ListIterator e = lst.end();
while(it != e) {
append(*it);
++it;
}
}
void ListImp::prependList(const List& lst)
{
ListIterator it = lst.end();
ListIterator e = lst.begin();
while(it != e) {
--it;
prepend(*it);
}
}
void ListImp::removeFirst()
{
erase(hook->next);
}
void ListImp::removeLast()
{
erase(hook->prev);
}
void ListImp::remove(const Value &obj)
{
if (obj.isNull())
return;
ListNode *n = hook->next;
while (n != hook) {
if (n->member == obj.imp()) {
erase(n);
return;
}
n = n->next;
}
}
void ListImp::clear()
{
ListNode *n = hook->next;
while (n != hook) {
n = n->next;
delete n->prev;
}
hook->next = hook;
hook->prev = hook;
}
ListImp *ListImp::copy() const
{
ListImp* newList = new ListImp;
ListIterator e = end();
ListIterator it = begin();
while(it != e) {
newList->append(*it);
++it;
}
//fprintf( stderr, "ListImp::copy returning newList=%p\n", newList );
return newList;
}
void ListImp::erase(ListNode *n)
{
if (n != hook) {
n->next->prev = n->prev;
n->prev->next = n->next;
delete n;
}
}
bool ListImp::isEmpty() const
{
return (hook->prev == hook);
}
int ListImp::size() const
{
int s = 0;
ListNode *node = hook;
while ((node = node->next) != hook)
s++;
return s;
}
Value ListImp::at(int i) const
{
if (i < 0 || i >= size())
return Undefined();
ListIterator it = begin();
int j = 0;
while ((j++ < i))
it++;
return *it;
}
ListImp *ListImp::emptyList = 0L;
ListImp *ListImp::empty()
{
if (!emptyList)
emptyList = new ListImp();
return emptyList;
}
// ------------------------------ ContextImp -----------------------------------
......@@ -877,8 +667,7 @@ void InterpreterImp::mark()
BooleanImp::staticTrue->mark();
if (BooleanImp::staticFalse && !BooleanImp::staticFalse->marked())
BooleanImp::staticFalse->mark();
if (ListImp::emptyList && !ListImp::emptyList->marked())
ListImp::emptyList->mark();
List::markEmptyList();
//fprintf( stderr, "InterpreterImp::mark this=%p global.imp()=%p\n", this, global.imp() );
if (global.imp())
global.imp()->mark();
......
......@@ -138,71 +138,6 @@ namespace KJS {
inline Number::Number(NumberImp *imp) : Value(imp) { }
// ---------------------------------------------------------------------------
// Internal type impls
// ---------------------------------------------------------------------------
/**
* @internal
*/
class ListNode {
friend class List;
friend class ListImp;
friend class ListIterator;
ListNode(Value val, ListNode *p, ListNode *n)
: member(val.imp()), prev(p), next(n) {};
ValueImp *member;
ListNode *prev, *next;
};
class ListImp : public ValueImp {
friend class ListIterator;
friend class List;
friend class InterpreterImp;
friend class ObjectImp;
private:
ListImp();
~ListImp();
Type type() const { return ListType; }
virtual void mark();
Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
bool toBoolean(ExecState *exec) const;
double toNumber(ExecState *exec) const;
UString toString(ExecState *exec) const;
Object toObject(ExecState *exec) const;
void append(const Value& val);
void prepend(const Value& val);
void appendList(const List& lst);
void prependList(const List& lst);
void removeFirst();
void removeLast();
void remove(const Value &val);
void clear();
ListImp *copy() const;
ListIterator begin() const { return ListIterator(hook->next); }
ListIterator end() const { return ListIterator(hook); }
// bool isEmpty() const { return (hook->prev == hook); }
bool isEmpty() const;
int size() const;
Value at(int i) const;
Value operator[](int i) const { return at(i); }
static ListImp* empty();
#ifdef KJS_DEBUG_MEM
static int count;
#endif
private:
void erase(ListNode *n);
ListNode *hook;
static ListImp *emptyList;
};
inline List::List(ListImp *imp) : Value(imp) { }
/**
* @short The "label set" in Ecma-262 spec
*/
......
......@@ -61,22 +61,19 @@ Object Object::dynamicCast(const Value &v)
// ------------------------------ ObjectImp ------------------------------------
ObjectImp::ObjectImp(const Object &proto)
: _prop(0), _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L), _scope(0)
: _prop(0), _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L), _scope(true)
{
//fprintf(stderr,"ObjectImp::ObjectImp %p\n",(void*)this);
_scope = ListImp::empty();
_scope->setGcAllowed();
_prop = new PropertyMap();
}
ObjectImp::ObjectImp()
ObjectImp::ObjectImp() :
_scope(true)
{
//fprintf(stderr,"ObjectImp::ObjectImp %p\n",(void*)this);
_prop = 0;
_proto = NullImp::staticNull;
_internalValue = 0L;
_scope = ListImp::empty();
_scope->setGcAllowed();
_prop = new PropertyMap();
}
......@@ -98,8 +95,8 @@ void ObjectImp::mark()
if (_internalValue && !_internalValue->marked())
_internalValue->mark();
if (_scope && !_scope->marked())
_scope->mark();
_scope.mark();
}
const ClassInfo *ObjectImp::classInfo() const
......@@ -390,8 +387,7 @@ const List ObjectImp::scope() const
void ObjectImp::setScope(const List &s)
{
if (_scope) _scope->setGcAllowed();
_scope = static_cast<ListImp*>(s.imp());
_scope = s;
}
ReferenceList ObjectImp::propList(ExecState *exec, bool recursive)
......
......@@ -587,7 +587,7 @@ namespace KJS {
PropertyMap *_prop;
ValueImp *_proto;
ValueImp *_internalValue;
ListImp *_scope;
List _scope;
};
/**
......
......@@ -38,6 +38,73 @@
using namespace KJS;
namespace KJS {
// ---------------------------------------------------------------------------
// Internal type impls
// ---------------------------------------------------------------------------
/**
* @internal
*/
class ListNode {
friend class List;
friend class ListImp;
friend class ListIterator;
ListNode(Value val, ListNode *p, ListNode *n)
: member(val.imp()), prev(p), next(n) {};
ValueImp *member;
ListNode *prev, *next;
};
class ListImp : public ValueImp {
friend class ListIterator;
friend class List;
friend class InterpreterImp;
friend class ObjectImp;
private:
ListImp();
~ListImp();
Type type() const { return ListType; }
virtual void mark();
Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
bool toBoolean(ExecState *exec) const;
double toNumber(ExecState *exec) const;
UString toString(ExecState *exec) const;
Object toObject(ExecState *exec) const;
void append(const Value& val);
void prepend(const Value& val);
void appendList(const List& lst);
void prependList(const List& lst);
void removeFirst();
void removeLast();
void remove(const Value &val);
void clear();
ListImp *copy() const;
ListIterator begin() const { return ListIterator(hook->next); }
ListIterator end() const { return ListIterator(hook); }
// bool isEmpty() const { return (hook->prev == hook); }
bool isEmpty() const;
int size() const;
Value at(int i) const;
Value operator[](int i) const { return at(i); }
static ListImp* empty();
#ifdef KJS_DEBUG_MEM
static int count;
#endif
private:
void erase(ListNode *n);
ListNode *hook;
static ListImp *emptyList;
};
}
// ------------------------------ ListIterator ---------------------------------
//d dont add ListIterator();
......@@ -56,13 +123,13 @@ ValueImp* ListIterator::operator->() const
return node->member;
}
// operator Value* () const { return node->member; }
// operator Value* () const { return node->member; }
Value ListIterator::operator*() const
{
return Value(node->member);
}
// operator Value*() const { return node->member; }
// operator Value*() const { return node->member; }
Value ListIterator::operator++()
{
node = node->next;
......@@ -101,10 +168,56 @@ bool ListIterator::operator!=(const ListIterator &it) const
// ------------------------------ List -----------------------------------------
List::List()
: Value(new ListImp())
List::List(bool needsMarking)
: Value(needsMarking ? ListImp::empty() : new ListImp()),
m_needsMarking(needsMarking)
{
if (m_needsMarking) {
imp()->deref();
}
}
List::List(const List& l)
: Value(l),
m_needsMarking(false)
{
}
List::List(ListImp *imp)
: Value(imp),
m_needsMarking(false)
{
}
List& List::operator=(const List& l)
{
if (m_needsMarking) {
imp()->ref();
}
Value::operator=(l);
if (m_needsMarking) {
imp()->deref();
}
return *this;
}
List::~List()
{
if (m_needsMarking) {
imp()->ref();
}
}
void List::mark()
{
//fprintf(stderr,"List::List() this=%p imp=%p refcount=%d\n",this,rep,rep->refcount);
if (!imp()->marked()) {
imp()->mark();
}
}
void List::append(const Value& val)
......@@ -195,3 +308,220 @@ void List::globalClear()
}
#endif
void List::markEmptyList()
{
if (ListImp::emptyList && !ListImp::emptyList->marked())
ListImp::emptyList->mark();
}
// ------------------------------ ListImp --------------------------------------
#ifdef KJS_DEBUG_MEM
int ListImp::count = 0;
#endif
Value ListImp::toPrimitive(ExecState */*exec*/, Type /*preferredType*/) const
{
// invalid for List
assert(false);
return Value();
}
bool ListImp::toBoolean(ExecState */*exec*/) const
{
// invalid for List
assert(false);
return false;
}
double ListImp::toNumber(ExecState */*exec*/) const
{
// invalid for List
assert(false);
return 0;
}
UString ListImp::toString(ExecState */*exec*/) const
{
// invalid for List
assert(false);
return UString::null;
}
Object ListImp::toObject(ExecState */*exec*/) const
{
// invalid for List
assert(false);
return Object();
}
ListImp::ListImp()
{
#ifdef KJS_DEBUG_MEM
count++;
#endif
hook = new ListNode(Null(), 0L, 0L);
hook->next = hook;
hook->prev = hook;
//fprintf(stderr,"ListImp::ListImp %p hook=%p\n",this,hook);
}
</