Commit 66092a36 authored by darin's avatar darin

JavaScriptCore:

	- reduced the creation of Value objects and hoisted the property map
        into Object for another gain of about 6%

        * JavaScriptCore.pbproj/project.pbxproj: Made property_map.h public.
        * kjs/array_object.cpp:
        (compareWithCompareFunctionForQSort): Don't wrap the ValueImp * in a Value
	just to add it to a list.
        (ArrayProtoFuncImp::call): Pass the globalObject directly so we don't have
	to ref/deref.
        * kjs/function.cpp:
        (FunctionImp::call): Use a reference for the global object to avoid ref/deref.
        (GlobalFuncImp::call): Ditto.
        * kjs/internal.cpp:
        (BooleanImp::toObject): Put the object directly into the list, don't create a Value.
        (StringImp::toObject): Ditto.
        (NumberImp::toObject): Ditto.
        (InterpreterImp::evaluate): Use a reference for the global object.
        * kjs/internal.h: Return a reference for the global object.
        * kjs/interpreter.cpp: (Interpreter::globalObject): Ditto.
        * kjs/interpreter.h: Ditto.
        * kjs/object.cpp: Use _prop directly in the object, not a separate pointer.
        * kjs/object.h: Ditto.
        * kjs/types.cpp: Added List methods that work directly with ValueImp.
        (List::append): Added a ValueImp version.
        (List::prepend): Ditto.
        (List::appendList): Work directly with the ValueImp's.
        (List::prependList): Ditto.
        (List::copy): Use appendList.
        (List::empty): Use a shared global List.
        * kjs/types.h: Update for above changes.

WebCore:

        * force-js-clean-timestamp: Another Object change.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2753 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c12f0487
2002-11-18 Darin Adler <darin@apple.com>
- reduced the creation of Value objects and hoisted the property map
into Object for another gain of about 6%
* JavaScriptCore.pbproj/project.pbxproj: Made property_map.h public.
* kjs/array_object.cpp:
(compareWithCompareFunctionForQSort): Don't wrap the ValueImp * in a Value
just to add it to a list.
(ArrayProtoFuncImp::call): Pass the globalObject directly so we don't have
to ref/deref.
* kjs/function.cpp:
(FunctionImp::call): Use a reference for the global object to avoid ref/deref.
(GlobalFuncImp::call): Ditto.
* kjs/internal.cpp:
(BooleanImp::toObject): Put the object directly into the list, don't create a Value.
(StringImp::toObject): Ditto.
(NumberImp::toObject): Ditto.
(InterpreterImp::evaluate): Use a reference for the global object.
* kjs/internal.h: Return a reference for the global object.
* kjs/interpreter.cpp: (Interpreter::globalObject): Ditto.
* kjs/interpreter.h: Ditto.
* kjs/object.cpp: Use _prop directly in the object, not a separate pointer.
* kjs/object.h: Ditto.
* kjs/types.cpp: Added List methods that work directly with ValueImp.
(List::append): Added a ValueImp version.
(List::prepend): Ditto.
(List::appendList): Work directly with the ValueImp's.
(List::prependList): Ditto.
(List::copy): Use appendList.
(List::empty): Use a shared global List.
* kjs/types.h: Update for above changes.
2002-11-18 Darin Adler <darin@apple.com>
* kjs/property_map.cpp: Oops, copyright goes to Apple, not me.
......
2002-11-18 Darin Adler <darin@apple.com>
- reduced the creation of Value objects and hoisted the property map
into Object for another gain of about 6%
* JavaScriptCore.pbproj/project.pbxproj: Made property_map.h public.
* kjs/array_object.cpp:
(compareWithCompareFunctionForQSort): Don't wrap the ValueImp * in a Value
just to add it to a list.
(ArrayProtoFuncImp::call): Pass the globalObject directly so we don't have
to ref/deref.
* kjs/function.cpp:
(FunctionImp::call): Use a reference for the global object to avoid ref/deref.
(GlobalFuncImp::call): Ditto.
* kjs/internal.cpp:
(BooleanImp::toObject): Put the object directly into the list, don't create a Value.
(StringImp::toObject): Ditto.
(NumberImp::toObject): Ditto.
(InterpreterImp::evaluate): Use a reference for the global object.
* kjs/internal.h: Return a reference for the global object.
* kjs/interpreter.cpp: (Interpreter::globalObject): Ditto.
* kjs/interpreter.h: Ditto.
* kjs/object.cpp: Use _prop directly in the object, not a separate pointer.
* kjs/object.h: Ditto.
* kjs/types.cpp: Added List methods that work directly with ValueImp.
(List::append): Added a ValueImp version.
(List::prepend): Ditto.
(List::appendList): Work directly with the ValueImp's.
(List::prependList): Ditto.
(List::copy): Use appendList.
(List::empty): Use a shared global List.
* kjs/types.h: Update for above changes.
2002-11-18 Darin Adler <darin@apple.com>
* kjs/property_map.cpp: Oops, copyright goes to Apple, not me.
......
2002-11-18 Darin Adler <darin@apple.com>
- reduced the creation of Value objects and hoisted the property map
into Object for another gain of about 6%
* JavaScriptCore.pbproj/project.pbxproj: Made property_map.h public.
* kjs/array_object.cpp:
(compareWithCompareFunctionForQSort): Don't wrap the ValueImp * in a Value
just to add it to a list.
(ArrayProtoFuncImp::call): Pass the globalObject directly so we don't have
to ref/deref.
* kjs/function.cpp:
(FunctionImp::call): Use a reference for the global object to avoid ref/deref.
(GlobalFuncImp::call): Ditto.
* kjs/internal.cpp:
(BooleanImp::toObject): Put the object directly into the list, don't create a Value.
(StringImp::toObject): Ditto.
(NumberImp::toObject): Ditto.
(InterpreterImp::evaluate): Use a reference for the global object.
* kjs/internal.h: Return a reference for the global object.
* kjs/interpreter.cpp: (Interpreter::globalObject): Ditto.
* kjs/interpreter.h: Ditto.
* kjs/object.cpp: Use _prop directly in the object, not a separate pointer.
* kjs/object.h: Ditto.
* kjs/types.cpp: Added List methods that work directly with ValueImp.
(List::append): Added a ValueImp version.
(List::prepend): Ditto.
(List::appendList): Work directly with the ValueImp's.
(List::prependList): Ditto.
(List::copy): Use appendList.
(List::empty): Use a shared global List.
* kjs/types.h: Update for above changes.
2002-11-18 Darin Adler <darin@apple.com>
* kjs/property_map.cpp: Oops, copyright goes to Apple, not me.
......
......@@ -1331,6 +1331,9 @@
fileRef = F692A87A0255597D01FF60F7;
isa = PBXBuildFile;
settings = {
ATTRIBUTES = (
Private,
);
};
};
F692A8B70255597D01FF60F7 = {
......
......@@ -229,8 +229,8 @@ static int compareWithCompareFunctionForQSort(const void *a, const void *b)
CompareWithCompareFunctionArguments *args = compareWithCompareFunctionArguments;
args->arguments.clear();
args->arguments.append(Value(*(ValueImp **)a));
args->arguments.append(Value(*(ValueImp **)b));
args->arguments.append(*(ValueImp **)a);
args->arguments.append(*(ValueImp **)b);
return args->compareFunction->call(args->exec, args->globalObject, args->arguments)
.toInt32(args->exec);
}
......@@ -530,8 +530,7 @@ Value ArrayProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args
List l;
l.append(jObj);
l.append(minObj);
Object thisObj = exec->interpreter()->globalObject();
cmp = sortFunction.call(exec,thisObj, l ).toInt32(exec);
cmp = sortFunction.call(exec, exec->interpreter()->globalObject(), l).toInt32(exec);
} else {
cmp = (jObj.toString(exec) < minObj.toString(exec)) ? -1 : 1;
}
......
......@@ -79,7 +79,7 @@ bool FunctionImp::implementsCall() const
Value FunctionImp::call(ExecState *exec, Object &thisObj, const List &args)
{
Object globalObj = exec->interpreter()->globalObject();
Object &globalObj = exec->interpreter()->globalObject();
Debugger *dbg = exec->interpreter()->imp()->debugger();
int sid = -1;
......@@ -368,9 +368,8 @@ Value GlobalFuncImp::call(ExecState *exec, Object &/*thisObj*/, const List &args
progNode->ref();
// enter a new execution context
Object glob(exec->interpreter()->globalObject());
Object thisVal(Object::dynamicCast(exec->context().thisValue()));
ContextImp *ctx = new ContextImp(glob,
ContextImp *ctx = new ContextImp(exec->interpreter()->globalObject(),
exec,
thisVal,
EvalCode,
......
......@@ -186,7 +186,7 @@ UString BooleanImp::toString(ExecState */*exec*/) const
Object BooleanImp::toObject(ExecState *exec) const
{
List args;
args.append(Boolean(const_cast<BooleanImp*>(this)));
args.append(const_cast<BooleanImp*>(this));
return Object::dynamicCast(exec->interpreter()->builtinBoolean().construct(exec,args));
}
......@@ -215,7 +215,7 @@ UString StringImp::toString(ExecState */*exec*/) const
Object StringImp::toObject(ExecState *exec) const
{
List args;
args.append(Value(const_cast<StringImp*>(this)));
args.append(const_cast<StringImp*>(this));
return Object::dynamicCast(exec->interpreter()->builtinString().construct(exec,args));
}
......@@ -244,7 +244,7 @@ UString NumberImp::toString(ExecState *) const
Object NumberImp::toObject(ExecState *exec) const
{
List args;
args.append(Number(const_cast<NumberImp*>(this)));
args.append(const_cast<NumberImp*>(this));
return Object::dynamicCast(exec->interpreter()->builtinNumber().construct(exec,args));
}
......@@ -734,7 +734,7 @@ Completion InterpreterImp::evaluate(const UString &code, const Value &thisV)
recursion++;
progNode->ref();
Object globalObj = globalObject();
Object &globalObj = globalObject();
Object thisObj = globalObject();
if (!thisV.isNull()) {
......
......@@ -240,7 +240,7 @@ namespace KJS {
InterpreterImp(Interpreter *interp, const Object &glob);
~InterpreterImp();
Object globalObject() const { return global; }
Object &globalObject() const { return const_cast<Object &>(global); }
Interpreter* interpreter() const { return m_interpreter; }
void initGlobalObject();
......
......@@ -108,7 +108,7 @@ Interpreter::~Interpreter()
delete rep;
}
Object Interpreter::globalObject() const
Object &Interpreter::globalObject() const
{
return rep->globalObject();
}
......
......@@ -145,7 +145,7 @@ namespace KJS {
* Returns the object that is used as the global object during all script
* execution performed by this interpreter
*/
Object globalObject() const;
Object &globalObject() const;
void initGlobalObject();
......
......@@ -37,7 +37,6 @@
#include "operations.h"
#include "error_object.h"
#include "nodes.h"
#include "property_map.h"
namespace KJS {
......@@ -61,26 +60,22 @@ Object Object::dynamicCast(const Value &v)
// ------------------------------ ObjectImp ------------------------------------
ObjectImp::ObjectImp(const Object &proto)
: _prop(0), _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L), _scope(true)
: _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L), _scope(true)
{
//fprintf(stderr,"ObjectImp::ObjectImp %p\n",(void*)this);
_prop = new PropertyMap();
}
ObjectImp::ObjectImp() :
_scope(true)
{
//fprintf(stderr,"ObjectImp::ObjectImp %p\n",(void*)this);
_prop = 0;
_proto = NullImp::staticNull;
_internalValue = 0L;
_prop = new PropertyMap();
}
ObjectImp::~ObjectImp()
{
//fprintf(stderr,"ObjectImp::~ObjectImp %p\n",(void*)this);
delete _prop;
}
void ObjectImp::mark()
......@@ -91,7 +86,7 @@ void ObjectImp::mark()
if (_proto && !_proto->marked())
_proto->mark();
_prop->mark();
_prop.mark();
if (_internalValue && !_internalValue->marked())
_internalValue->mark();
......@@ -170,7 +165,7 @@ Value ObjectImp::get(ExecState *exec, unsigned propertyName) const
// to look up in the prototype, it might already exist there)
ValueImp* ObjectImp::getDirect(const UString& propertyName) const
{
return _prop->get(propertyName);
return _prop.get(propertyName);
}
// ECMA 8.6.2.2
......@@ -198,7 +193,7 @@ void ObjectImp::put(ExecState *exec, const UString &propertyName,
return;
}
_prop->put(propertyName,value.imp(),attr);
_prop.put(propertyName,value.imp(),attr);
}
void ObjectImp::put(ExecState *exec, unsigned propertyName,
......@@ -211,7 +206,7 @@ void ObjectImp::put(ExecState *exec, unsigned propertyName,
bool ObjectImp::canPut(ExecState *, const UString &propertyName) const
{
int attributes;
ValueImp *v = _prop->get(propertyName, attributes);
ValueImp *v = _prop.get(propertyName, attributes);
if (v)
return!(attributes & ReadOnly);
......@@ -228,7 +223,7 @@ bool ObjectImp::canPut(ExecState *, const UString &propertyName) const
// ECMA 8.6.2.4
bool ObjectImp::hasProperty(ExecState *exec, const UString &propertyName) const
{
if (_prop->get(propertyName))
if (_prop.get(propertyName))
return true;
// Look in the static hashtable of properties
......@@ -253,11 +248,11 @@ bool ObjectImp::hasProperty(ExecState *exec, unsigned propertyName) const
bool ObjectImp::deleteProperty(ExecState */*exec*/, const UString &propertyName)
{
int attributes;
ValueImp *v = _prop->get(propertyName, attributes);
ValueImp *v = _prop.get(propertyName, attributes);
if (v) {
if ((attributes & DontDelete))
return false;
_prop->remove(propertyName);
_prop.remove(propertyName);
return true;
}
......@@ -275,7 +270,7 @@ bool ObjectImp::deleteProperty(ExecState *exec, unsigned propertyName)
void ObjectImp::deleteAllProperties( ExecState * )
{
_prop->clear();
_prop.clear();
}
// ECMA 8.6.2.6
......@@ -396,7 +391,7 @@ ReferenceList ObjectImp::propList(ExecState *exec, bool recursive)
if (_proto && _proto->dispatchType() == ObjectType && recursive)
list = static_cast<ObjectImp*>(_proto)->propList(exec,recursive);
_prop->addEnumerablesToReferenceList(list, Object(this));
_prop.addEnumerablesToReferenceList(list, Object(this));
// Add properties from the static hashtable of properties
const ClassInfo *info = classInfo();
......
......@@ -40,10 +40,10 @@
#include "value.h"
#include "types.h"
#include "reference_list.h"
#include "property_map.h"
namespace KJS {
class PropertyMap;
class HashTable;
class HashEntry;
class ListImp;
......@@ -582,7 +582,7 @@ namespace KJS {
ValueImp* getDirect(const UString& propertyName) const;
private:
const HashEntry* findPropertyHashEntry( const UString& propertyName ) const;
PropertyMap *_prop;
PropertyMap _prop;
ValueImp *_proto;
ValueImp *_internalValue;
List _scope;
......
......@@ -46,6 +46,8 @@ namespace KJS {
protected:
ListNode(const Value &val, ListNode *p, ListNode *n)
: member(val.imp()), prev(p), next(n) {};
ListNode(ValueImp *val, ListNode *p, ListNode *n)
: member(val), prev(p), next(n) {};
ValueImp *member;
ListNode *prev, *next;
};
......@@ -61,27 +63,16 @@ namespace KJS {
// ------------------------------ ListIterator ---------------------------------
ListIterator::ListIterator(ListNode *n) : node(n)
{
}
ListIterator::ListIterator(const List &l)
: node(l.hook->next)
{
}
ValueImp* ListIterator::operator->() const
{
return node->member;
}
// operator Value* () const { return node->member; }
Value ListIterator::operator*() const
{
return Value(node->member);
}
// operator Value*() const { return node->member; }
Value ListIterator::operator++()
{
node = node->next;
......@@ -108,16 +99,6 @@ Value ListIterator::operator--(int)
return Value(n->member);
}
bool ListIterator::operator==(const ListIterator &it) const
{
return (node==it.node);
}
bool ListIterator::operator!=(const ListIterator &it) const
{
return (node!=it.node);
}
// ------------------------------ List -----------------------------------------
List::List(bool needsMarking)
......@@ -182,6 +163,16 @@ void List::append(const Value& val)
hook->prev = n;
}
void List::append(ValueImp *val)
{
ListNode *n = new ListNode(val, hook->prev, hook);
if (!m_needsMarking) {
val->ref();
}
hook->prev->next = n;
hook->prev = n;
}
void List::prepend(const Value& val)
{
ListNode *n = new ListNode(val, hook, hook->next);
......@@ -192,23 +183,33 @@ void List::prepend(const Value& val)
hook->next = n;
}
void List::prepend(ValueImp *val)
{
ListNode *n = new ListNode(val, hook->prev, hook);
if (!m_needsMarking) {
val->ref();
}
hook->next->prev = n;
hook->next = n;
}
void List::appendList(const List& lst)
{
ListIterator it = lst.begin();
ListIterator e = lst.end();
while(it != e) {
append(*it);
++it;
ListNode *otherHook = lst.hook;
ListNode *o = otherHook->next;
while (o != otherHook) {
append(o->member);
o = o->next;
}
}
void List::prependList(const List& lst)
{
ListIterator it = lst.end();
ListIterator e = lst.begin();
while(it != e) {
--it;
prepend(*it);
ListNode *otherHook = lst.hook;
ListNode *o = otherHook->prev;
while (o != otherHook) {
prepend(o->member);
o = o->prev;
}
}
......@@ -260,15 +261,7 @@ void List::clearInternal()
List List::copy() const
{
List newList;
ListIterator e = end();
ListIterator it = begin();
while(it != e) {
newList.append(*it);
++it;
}
newList.appendList(*this);
return newList;
}
......@@ -315,9 +308,10 @@ Value List::operator[](int i) const
return at(i);
}
const List List::empty()
const List &List::empty()
{
return List();
static List l;
return l;
}
......
......@@ -42,8 +42,8 @@ namespace KJS {
*/
class ListIterator {
friend class List;
ListIterator();
ListIterator(ListNode *n);
ListIterator() : node(0) { }
ListIterator(ListNode *n) : node(n) { }
public:
/**
* Construct an iterator that points to the first element of the list.
......@@ -55,13 +55,7 @@ namespace KJS {
* @return A pointer to the element the iterator operates on.
*/
ValueImp* operator->() const;
// operator Value* () const { return node->member; }
Value operator*() const;
/**
* Conversion to @ref KJS::Value*
* @return A pointer to the element the iterator operates on.
*/
// operator Value*() const { return node->member; }
/**
* Postfix increment operator.
* @return The element after the increment.
......@@ -84,12 +78,12 @@ namespace KJS {
* @return True if the two iterators operate on the same list element.
* False otherwise.
*/
bool operator==(const ListIterator &it) const;
bool operator==(const ListIterator &it) const { return node == it.node; }
/**
* Check for inequality with another iterator.
* @return True if the two iterators operate on different list elements.
*/
bool operator!=(const ListIterator &it) const;
bool operator!=(const ListIterator &it) const { return node != it.node; }
private:
ListNode *node;
};
......@@ -119,12 +113,14 @@ namespace KJS {
* @param val Pointer to object.
*/
void append(const Value& val);
void append(ValueImp *val);
/**
* Insert an object at the beginning of the list.
*
* @param val Pointer to object.
*/
void prepend(const Value& val);
void prepend(ValueImp *val);
/**
* Appends the items of another list at the end of this one.
*/
......@@ -146,6 +142,7 @@ namespace KJS {
* Remove val from list.
*/
void remove(const Value &val);
void remove(ValueImp *val);
/**
* Remove all elements from the list.
*/
......@@ -189,7 +186,7 @@ namespace KJS {
* Returns a pointer to a static instance of an empty list. Useful if a
* function has a @ref KJS::List parameter.
*/
static const List empty();
static const List &empty();
#ifdef KJS_DEBUG_MEM
static void globalClear();
#endif
......
2002-11-18 Darin Adler <darin@apple.com>
* force-js-clean-timestamp: Another Object change.
2002-11-18 David Hyatt <hyatt@apple.com>
Implement phased painting to correct the paint order of blocks,
......
2002-11-18 Darin Adler <darin@apple.com>
* force-js-clean-timestamp: Another Object change.
2002-11-18 David Hyatt <hyatt@apple.com>
Implement phased painting to correct the paint order of blocks,
......
2002-11-18 Darin Adler <darin@apple.com>
* force-js-clean-timestamp: Another Object change.
2002-11-18 David Hyatt <hyatt@apple.com>
Implement phased painting to correct the paint order of blocks,
......
Object field removed 11/18 - Darin
property maps hoisted in Object 11/18 - Darin
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment