Commit 57017199 authored by darin's avatar darin

- added a feature for Richard to use in his back/forward cache

        * kjs/object.h: Added save/restoreProperties.
        * kjs/property_map.h: Here too.
        * kjs/property_map.cpp: Here too.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2794 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 68860175
2002-11-20 Darin Adler <darin@apple.com>
- added a feature for Richard to use in his back/forward cache
* kjs/object.h: Added save/restoreProperties.
* kjs/property_map.h: Here too.
* kjs/property_map.cpp: Here too.
2002-11-20 Darin Adler <darin@apple.com>
- created argument list objects only on demand for a 7.5% speedup
......
2002-11-20 Darin Adler <darin@apple.com>
- added a feature for Richard to use in his back/forward cache
* kjs/object.h: Added save/restoreProperties.
* kjs/property_map.h: Here too.
* kjs/property_map.cpp: Here too.
2002-11-20 Darin Adler <darin@apple.com>
- created argument list objects only on demand for a 7.5% speedup
......
2002-11-20 Darin Adler <darin@apple.com>
- added a feature for Richard to use in his back/forward cache
* kjs/object.h: Added save/restoreProperties.
* kjs/property_map.h: Here too.
* kjs/property_map.cpp: Here too.
2002-11-20 Darin Adler <darin@apple.com>
- created argument list objects only on demand for a 7.5% speedup
......
......@@ -80,7 +80,7 @@ namespace KJS {
*/
void *dummy;
};
/**
* Represents an Object. This is a wrapper for ObjectImp
*/
......@@ -357,6 +357,9 @@ namespace KJS {
* @param v The new internal value
*/
void setInternalValue(const Value &v);
void saveProperties(SavedProperties &p) const;
void restoreProperties(const SavedProperties &p);
};
inline Object Value::toObject(ExecState *exec) const { return rep->dispatchToObject(exec); }
......@@ -589,6 +592,9 @@ namespace KJS {
{ return _prop.get(propertyName); }
void putDirect(const Identifier &propertyName, ValueImp *value, int attr = 0);
void putDirect(const Identifier &propertyName, int value, int attr = 0);
void saveProperties(SavedProperties &p) const { _prop.save(p); }
void restoreProperties(const SavedProperties &p) { _prop.restore(p); }
private:
const HashEntry* findPropertyHashEntry( const Identifier& propertyName ) const;
......@@ -713,6 +719,11 @@ namespace KJS {
inline void Object::setInternalValue(const Value &v)
{ imp()->setInternalValue(v); }
inline void Object::saveProperties(SavedProperties &p) const
{ imp()->saveProperties(p); }
inline void Object::restoreProperties(const SavedProperties &p)
{ imp()->restoreProperties(p); }
}; // namespace
#endif // _KJS_OBJECT_H_
......@@ -25,11 +25,17 @@
#include "object.h"
#include "reference_list.h"
// At the time I added this, the optimization still gave a 1.5% performance boost.
// At the time I added this switch, the optimization still gave a 1.5% performance boost so I couldn't remove it.
#define USE_SINGLE_ENTRY 1
namespace KJS {
class SavedProperty {
public:
Identifier key;
Value value;
};
// Algorithm concepts from Algorithms in C++, Sedgewick.
PropertyMap::PropertyMap() : _tableSize(0), _table(0), _keyCount(0)
......@@ -281,4 +287,45 @@ void PropertyMap::addEnumerablesToReferenceList(ReferenceList &list, const Objec
}
}
void PropertyMap::save(SavedProperties &p) const
{
int count = 0;
#if USE_SINGLE_ENTRY
if (_singleEntry.key)
++count;
#endif
for (int i = 0; i != _tableSize; ++i)
if (_table[i].key && _table[i].attributes == 0)
++count;
delete [] p._properties;
if (count == 0) {
p._properties = 0;
return;
}
p._properties = new SavedProperty [count];
SavedProperty *prop = p._properties;
#if USE_SINGLE_ENTRY
if (_singleEntry.key) {
prop->key = Identifier(_singleEntry.key);
prop->value = Value(_singleEntry.value);
++prop;
}
#endif
for (int i = 0; i != _tableSize; ++i)
if (_table[i].key && _table[i].attributes == 0) {
prop->key = Identifier(_table[i].key);
prop->value = Value(_table[i].value);
}
}
void PropertyMap::restore(const SavedProperties &p)
{
for (int i = 0; i != p._count; ++i)
put(p._properties[i].key, p._properties[i].value.imp(), 0);
}
} // namespace KJS
......@@ -31,6 +31,22 @@ namespace KJS {
class ReferenceList;
class ValueImp;
class SavedProperty;
class SavedProperties {
friend class PropertyMap;
public:
SavedProperties() : _count(0), _properties(0) { }
~SavedProperties();
private:
int _count;
SavedProperty *_properties;
SavedProperties(const SavedProperties&);
SavedProperties& operator=(const SavedProperties&);
};
struct PropertyMapHashTableEntry
{
PropertyMapHashTableEntry() : key(0) { }
......@@ -54,6 +70,9 @@ namespace KJS {
void mark() const;
void addEnumerablesToReferenceList(ReferenceList &, const Object &) const;
void save(SavedProperties &) const;
void restore(const SavedProperties &p);
private:
int hash(const UString::Rep *) const;
static bool keysMatch(const UString::Rep *, const UString::Rep *);
......
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