[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.18-1-697-g2f78b87
barraclough at apple.com
barraclough at apple.com
Wed Jan 20 22:25:30 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit db2c512d9f0bdcd7eb05d3777a74e72bf58a6acc
Author: barraclough at apple.com <barraclough at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Jan 15 06:43:21 2010 +0000
JavaScriptCore: Make naming & behaviour of UString[Impl] methods more consistent.
https://bugs.webkit.org/show_bug.cgi?id=33702
Reviewed by Sam Weinig.
UString::create() creates a copy of the UChar* passed, but UStringImpl::create() assumes
that it should assume ownership of the provided buffer (with UString::createNonCopying()
and UStringImpl::createCopying() providing the alternate behaviours). Unify on create()
taking a copy of the provided buffer. For non-copying cases, use the name 'adopt', and
make this method take a Vector<UChar>&. For cases where non-copying construction was being
used, other than from a Vector<UChar>, change the code to allocate the storage along with
the UStringImpl using UStringImpl::createUninitialized(). (The adopt() method also more
closely matches that of WebCore::StringImpl).
Also, UString::createUninitialized() and UStringImpl::createUninitialized() have incompatible
behaviours, in that the UString form sets the provided UChar* to a null or non-null value to
indicate success or failure, but UStringImpl uses the returned PassRefPtr<UStringImpl> to
indicate when allocation has failed (potentially leaving the output Char* uninitialized).
This is also incompatible with WebCore::StringImpl's behaviour, in that
StringImpl::createUninitialized() will CRASH() if unable to allocate. Some uses of
createUninitialized() in JSC are unsafe, since they do not test the result for null.
UStringImpl's indication is preferable, since we may want a successful call to set the result
buffer to 0 (specifically, StringImpl returns 0 for the buffer where createUninitialized()
returns the empty string, which seems reasonable to catch bugs early). UString's method
cannot support UStringImpl's behaviour directly, since it returns an object rather than a
pointer.
- remove UString::createUninitialized(), replace with calls to UStringImpl::createUninitialized()
- create a UStringImpl::tryCreateUninitialized() form UStringImpl::createUninitialized(),
with current behaviour, make createUninitialized() crash on failure to allocate.
- make cases in JSC that do not check the result call createUninitialized(), and cases that do
check call tryCreateUninitialized().
Rename computedHash() to existingHash(), to bring this in line wih WebCore::StringImpl.
* API/JSClassRef.cpp:
(OpaqueJSClassContextData::OpaqueJSClassContextData):
* JavaScriptCore.exp:
* runtime/ArrayPrototype.cpp:
(JSC::arrayProtoFuncToString):
* runtime/Identifier.cpp:
(JSC::CStringTranslator::translate):
(JSC::UCharBufferTranslator::translate):
* runtime/JSString.cpp:
(JSC::JSString::resolveRope):
* runtime/Lookup.cpp:
(JSC::HashTable::createTable):
* runtime/Lookup.h:
(JSC::HashTable::entry):
* runtime/StringBuilder.h:
(JSC::StringBuilder::release):
* runtime/StringConstructor.cpp:
(JSC::stringFromCharCodeSlowCase):
* runtime/StringPrototype.cpp:
(JSC::substituteBackreferencesSlow):
(JSC::stringProtoFuncToLowerCase):
(JSC::stringProtoFuncToUpperCase):
(JSC::stringProtoFuncFontsize):
(JSC::stringProtoFuncLink):
* runtime/Structure.cpp:
(JSC::Structure::despecifyDictionaryFunction):
(JSC::Structure::get):
(JSC::Structure::despecifyFunction):
(JSC::Structure::put):
(JSC::Structure::remove):
(JSC::Structure::insertIntoPropertyMapHashTable):
(JSC::Structure::checkConsistency):
* runtime/Structure.h:
(JSC::Structure::get):
* runtime/StructureTransitionTable.h:
(JSC::StructureTransitionTableHash::hash):
* runtime/UString.cpp:
(JSC::createRep):
(JSC::UString::UString):
(JSC::UString::spliceSubstringsWithSeparators):
(JSC::UString::replaceRange):
(JSC::UString::operator=):
* runtime/UString.h:
(JSC::UString::adopt):
(JSC::IdentifierRepHash::hash):
(JSC::makeString):
* runtime/UStringImpl.h:
(JSC::UStringImpl::adopt):
(JSC::UStringImpl::create):
(JSC::UStringImpl::createUninitialized):
(JSC::UStringImpl::tryCreateUninitialized):
(JSC::UStringImpl::existingHash):
WebCore: Rubber stamped by Sam Weinig.
Make naming & behaviour of UString[Impl] methods more consistent.
https://bugs.webkit.org/show_bug.cgi?id=33702
WebCore change reflecting UString method name change computedHash() -> existingHash().
* platform/text/AtomicString.cpp:
(WebCore::AtomicString::add):
(WebCore::AtomicString::find):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53320 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/API/JSClassRef.cpp b/JavaScriptCore/API/JSClassRef.cpp
index 6306fb0..e443dc6 100644
--- a/JavaScriptCore/API/JSClassRef.cpp
+++ b/JavaScriptCore/API/JSClassRef.cpp
@@ -152,7 +152,7 @@ OpaqueJSClassContextData::OpaqueJSClassContextData(OpaqueJSClass* jsClass)
ASSERT(!it->first->isIdentifier());
// Use a local variable here to sidestep an RVCT compiler bug.
StaticValueEntry* entry = new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes);
- staticValues->add(UString::Rep::createCopying(it->first->data(), it->first->size()), entry);
+ staticValues->add(UString::Rep::create(it->first->data(), it->first->size()), entry);
}
@@ -167,7 +167,7 @@ OpaqueJSClassContextData::OpaqueJSClassContextData(OpaqueJSClass* jsClass)
ASSERT(!it->first->isIdentifier());
// Use a local variable here to sidestep an RVCT compiler bug.
StaticFunctionEntry* entry = new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes);
- staticFunctions->add(UString::Rep::createCopying(it->first->data(), it->first->size()), entry);
+ staticFunctions->add(UString::Rep::create(it->first->data(), it->first->size()), entry);
}
} else
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 1069b2f..d4b6d5d 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,92 @@
+2010-01-14 Gavin Barraclough <barraclough at apple.com>
+
+ Reviewed by Sam Weinig.
+
+ Make naming & behaviour of UString[Impl] methods more consistent.
+ https://bugs.webkit.org/show_bug.cgi?id=33702
+
+ UString::create() creates a copy of the UChar* passed, but UStringImpl::create() assumes
+ that it should assume ownership of the provided buffer (with UString::createNonCopying()
+ and UStringImpl::createCopying() providing the alternate behaviours). Unify on create()
+ taking a copy of the provided buffer. For non-copying cases, use the name 'adopt', and
+ make this method take a Vector<UChar>&. For cases where non-copying construction was being
+ used, other than from a Vector<UChar>, change the code to allocate the storage along with
+ the UStringImpl using UStringImpl::createUninitialized(). (The adopt() method also more
+ closely matches that of WebCore::StringImpl).
+
+ Also, UString::createUninitialized() and UStringImpl::createUninitialized() have incompatible
+ behaviours, in that the UString form sets the provided UChar* to a null or non-null value to
+ indicate success or failure, but UStringImpl uses the returned PassRefPtr<UStringImpl> to
+ indicate when allocation has failed (potentially leaving the output Char* uninitialized).
+ This is also incompatible with WebCore::StringImpl's behaviour, in that
+ StringImpl::createUninitialized() will CRASH() if unable to allocate. Some uses of
+ createUninitialized() in JSC are unsafe, since they do not test the result for null.
+ UStringImpl's indication is preferable, since we may want a successful call to set the result
+ buffer to 0 (specifically, StringImpl returns 0 for the buffer where createUninitialized()
+ returns the empty string, which seems reasonable to catch bugs early). UString's method
+ cannot support UStringImpl's behaviour directly, since it returns an object rather than a
+ pointer.
+ - remove UString::createUninitialized(), replace with calls to UStringImpl::createUninitialized()
+ - create a UStringImpl::tryCreateUninitialized() form UStringImpl::createUninitialized(),
+ with current behaviour, make createUninitialized() crash on failure to allocate.
+ - make cases in JSC that do not check the result call createUninitialized(), and cases that do
+ check call tryCreateUninitialized().
+
+ Rename computedHash() to existingHash(), to bring this in line wih WebCore::StringImpl.
+
+ * API/JSClassRef.cpp:
+ (OpaqueJSClassContextData::OpaqueJSClassContextData):
+ * JavaScriptCore.exp:
+ * runtime/ArrayPrototype.cpp:
+ (JSC::arrayProtoFuncToString):
+ * runtime/Identifier.cpp:
+ (JSC::CStringTranslator::translate):
+ (JSC::UCharBufferTranslator::translate):
+ * runtime/JSString.cpp:
+ (JSC::JSString::resolveRope):
+ * runtime/Lookup.cpp:
+ (JSC::HashTable::createTable):
+ * runtime/Lookup.h:
+ (JSC::HashTable::entry):
+ * runtime/StringBuilder.h:
+ (JSC::StringBuilder::release):
+ * runtime/StringConstructor.cpp:
+ (JSC::stringFromCharCodeSlowCase):
+ * runtime/StringPrototype.cpp:
+ (JSC::substituteBackreferencesSlow):
+ (JSC::stringProtoFuncToLowerCase):
+ (JSC::stringProtoFuncToUpperCase):
+ (JSC::stringProtoFuncFontsize):
+ (JSC::stringProtoFuncLink):
+ * runtime/Structure.cpp:
+ (JSC::Structure::despecifyDictionaryFunction):
+ (JSC::Structure::get):
+ (JSC::Structure::despecifyFunction):
+ (JSC::Structure::put):
+ (JSC::Structure::remove):
+ (JSC::Structure::insertIntoPropertyMapHashTable):
+ (JSC::Structure::checkConsistency):
+ * runtime/Structure.h:
+ (JSC::Structure::get):
+ * runtime/StructureTransitionTable.h:
+ (JSC::StructureTransitionTableHash::hash):
+ * runtime/UString.cpp:
+ (JSC::createRep):
+ (JSC::UString::UString):
+ (JSC::UString::spliceSubstringsWithSeparators):
+ (JSC::UString::replaceRange):
+ (JSC::UString::operator=):
+ * runtime/UString.h:
+ (JSC::UString::adopt):
+ (JSC::IdentifierRepHash::hash):
+ (JSC::makeString):
+ * runtime/UStringImpl.h:
+ (JSC::UStringImpl::adopt):
+ (JSC::UStringImpl::create):
+ (JSC::UStringImpl::createUninitialized):
+ (JSC::UStringImpl::tryCreateUninitialized):
+ (JSC::UStringImpl::existingHash):
+
2010-01-13 Kent Hansen <kent.hansen at nokia.com>
Reviewed by Oliver Hunt.
diff --git a/JavaScriptCore/JavaScriptCore.exp b/JavaScriptCore/JavaScriptCore.exp
index e13e2e1..ff12845 100644
--- a/JavaScriptCore/JavaScriptCore.exp
+++ b/JavaScriptCore/JavaScriptCore.exp
@@ -105,6 +105,7 @@ __ZN3JSC11JSByteArrayC1EPNS_9ExecStateEN3WTF17NonNullPassRefPtrINS_9StructureEEE
__ZN3JSC11ParserArena5resetEv
__ZN3JSC11UStringImpl12sharedBufferEv
__ZN3JSC11UStringImpl6s_nullE
+__ZN3JSC11UStringImpl7s_emptyE
__ZN3JSC11UStringImplD1Ev
__ZN3JSC11checkSyntaxEPNS_9ExecStateERKNS_10SourceCodeE
__ZN3JSC12DateInstance4infoE
@@ -232,7 +233,6 @@ __ZN3JSC7Profile10restoreAllEv
__ZN3JSC7Profile5focusEPKNS_11ProfileNodeE
__ZN3JSC7Profile7excludeEPKNS_11ProfileNodeE
__ZN3JSC7Profile7forEachEMNS_11ProfileNodeEFvvE
-__ZN3JSC7UString16createNonCopyingEPti
__ZN3JSC7UString4fromEd
__ZN3JSC7UString4fromEi
__ZN3JSC7UString4fromEj
diff --git a/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def b/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
index d21b22a..e2ba7c7 100644
--- a/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
+++ b/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
@@ -76,7 +76,6 @@ EXPORTS
?createInheritorID at JSObject@JSC@@AAEPAVStructure at 2@XZ
?createInterruptedExecutionException at JSC@@YA?AVJSValue at 1@PAVJSGlobalData at 1@@Z
?createLeaked at JSGlobalData@JSC@@SA?AV?$PassRefPtr at VJSGlobalData@JSC@@@WTF@@XZ
- ?createNonCopying at UString@JSC@@SA?AV12 at PA_WH@Z
?createSingleCharacterString at SmallStrings@JSC@@AAEXPAVJSGlobalData at 2@E at Z
?createStackOverflowError at JSC@@YA?AVJSValue at 1@PAVExecState at 1@@Z
?createStructure at JSByteArray@JSC@@SA?AV?$PassRefPtr at VStructure@JSC@@@WTF@@VJSValue at 2@@Z
diff --git a/JavaScriptCore/runtime/ArrayPrototype.cpp b/JavaScriptCore/runtime/ArrayPrototype.cpp
index 2086f98..ce814b2 100644
--- a/JavaScriptCore/runtime/ArrayPrototype.cpp
+++ b/JavaScriptCore/runtime/ArrayPrototype.cpp
@@ -204,8 +204,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState* exec, JSObject*, JSValue
buffer.append(rep->data(), rep->size());
}
ASSERT(buffer.size() == totalSize);
- unsigned finalSize = buffer.size();
- return jsString(exec, UString::createNonCopying(buffer.releaseBuffer(), finalSize));
+ return jsString(exec, UString::adopt(buffer));
}
JSValue JSC_HOST_CALL arrayProtoFuncToLocaleString(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
diff --git a/JavaScriptCore/runtime/Identifier.cpp b/JavaScriptCore/runtime/Identifier.cpp
index a25c0cc..747c4ac 100644
--- a/JavaScriptCore/runtime/Identifier.cpp
+++ b/JavaScriptCore/runtime/Identifier.cpp
@@ -112,13 +112,11 @@ struct CStringTranslator {
static void translate(UString::Rep*& location, const char* c, unsigned hash)
{
size_t length = strlen(c);
- UChar* d = static_cast<UChar*>(fastMalloc(sizeof(UChar) * length));
+ UChar* d;
+ UString::Rep* r = UString::Rep::createUninitialized(length, d).releaseRef();
for (size_t i = 0; i != length; i++)
d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
-
- UString::Rep* r = UString::Rep::create(d, static_cast<int>(length)).releaseRef();
r->setHash(hash);
-
location = r;
}
};
@@ -177,13 +175,11 @@ struct UCharBufferTranslator {
static void translate(UString::Rep*& location, const UCharBuffer& buf, unsigned hash)
{
- UChar* d = static_cast<UChar*>(fastMalloc(sizeof(UChar) * buf.length));
+ UChar* d;
+ UString::Rep* r = UString::Rep::createUninitialized(buf.length, d).releaseRef();
for (unsigned i = 0; i != buf.length; i++)
d[i] = buf.s[i];
-
- UString::Rep* r = UString::Rep::create(d, buf.length).releaseRef();
r->setHash(hash);
-
location = r;
}
};
diff --git a/JavaScriptCore/runtime/JSString.cpp b/JavaScriptCore/runtime/JSString.cpp
index 69164f8..d180339 100644
--- a/JavaScriptCore/runtime/JSString.cpp
+++ b/JavaScriptCore/runtime/JSString.cpp
@@ -96,8 +96,9 @@ void JSString::resolveRope(ExecState* exec) const
// Allocate the buffer to hold the final string, position initially points to the end.
UChar* buffer;
- m_value = UString::createUninitialized(m_stringLength, buffer);
- if (!buffer) {
+ if (PassRefPtr<UStringImpl> newImpl = UStringImpl::tryCreateUninitialized(m_stringLength, buffer))
+ m_value = newImpl;
+ else {
for (unsigned i = 0; i < m_ropeLength; ++i)
m_fibers[i].deref();
m_ropeLength = 0;
diff --git a/JavaScriptCore/runtime/Lookup.cpp b/JavaScriptCore/runtime/Lookup.cpp
index 8359ff7..4e9e086 100644
--- a/JavaScriptCore/runtime/Lookup.cpp
+++ b/JavaScriptCore/runtime/Lookup.cpp
@@ -34,7 +34,7 @@ void HashTable::createTable(JSGlobalData* globalData) const
entries[i].setKey(0);
for (int i = 0; values[i].key; ++i) {
UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef();
- int hashIndex = identifier->computedHash() & compactHashSizeMask;
+ int hashIndex = identifier->existingHash() & compactHashSizeMask;
HashEntry* entry = &entries[hashIndex];
if (entry->key()) {
diff --git a/JavaScriptCore/runtime/Lookup.h b/JavaScriptCore/runtime/Lookup.h
index 4d70689..e673c09 100644
--- a/JavaScriptCore/runtime/Lookup.h
+++ b/JavaScriptCore/runtime/Lookup.h
@@ -144,7 +144,7 @@ namespace JSC {
{
ASSERT(table);
- const HashEntry* entry = &table[identifier.ustring().rep()->computedHash() & compactHashSizeMask];
+ const HashEntry* entry = &table[identifier.ustring().rep()->existingHash() & compactHashSizeMask];
if (!entry->key())
return 0;
diff --git a/JavaScriptCore/runtime/StringBuilder.h b/JavaScriptCore/runtime/StringBuilder.h
index b6a1406..8e18d37 100644
--- a/JavaScriptCore/runtime/StringBuilder.h
+++ b/JavaScriptCore/runtime/StringBuilder.h
@@ -69,8 +69,7 @@ public:
UString release()
{
buffer.shrinkToFit();
- size_t length = buffer.size();
- return UString::createNonCopying(buffer.releaseBuffer(), length);
+ return UString::adopt(buffer);
}
private:
diff --git a/JavaScriptCore/runtime/StringConstructor.cpp b/JavaScriptCore/runtime/StringConstructor.cpp
index 8165ff2..c7b62bf 100644
--- a/JavaScriptCore/runtime/StringConstructor.cpp
+++ b/JavaScriptCore/runtime/StringConstructor.cpp
@@ -30,12 +30,12 @@ namespace JSC {
static NEVER_INLINE JSValue stringFromCharCodeSlowCase(ExecState* exec, const ArgList& args)
{
- UChar* buf = static_cast<UChar*>(fastMalloc(args.size() * sizeof(UChar)));
- UChar* p = buf;
- ArgList::const_iterator end = args.end();
- for (ArgList::const_iterator it = args.begin(); it != end; ++it)
- *p++ = static_cast<UChar>((*it).toUInt32(exec));
- return jsString(exec, UString::createNonCopying(buf, p - buf));
+ unsigned length = args.size();
+ UChar* buf;
+ PassRefPtr<UStringImpl> impl = UStringImpl::createUninitialized(length, buf);
+ for (unsigned i = 0; i < length; ++i)
+ buf[i] = static_cast<UChar>(args.at(i).toUInt32(exec));
+ return jsString(exec, impl);
}
static JSValue JSC_HOST_CALL stringFromCharCode(ExecState* exec, JSObject*, JSValue, const ArgList& args)
diff --git a/JavaScriptCore/runtime/StringPrototype.cpp b/JavaScriptCore/runtime/StringPrototype.cpp
index 6498564..d002e07 100644
--- a/JavaScriptCore/runtime/StringPrototype.cpp
+++ b/JavaScriptCore/runtime/StringPrototype.cpp
@@ -211,8 +211,7 @@ static NEVER_INLINE UString substituteBackreferencesSlow(const UString& replacem
substitutedReplacement.append(replacement.data() + offset, replacement.size() - offset);
substitutedReplacement.shrinkToFit();
- unsigned size = substitutedReplacement.size();
- return UString::createNonCopying(substitutedReplacement.releaseBuffer(), size);
+ return UString::adopt(substitutedReplacement);
}
static inline UString substituteBackreferences(const UString& replacement, const UString& source, const int* ovector, RegExp* reg)
@@ -722,7 +721,7 @@ JSValue JSC_HOST_CALL stringProtoFuncToLowerCase(ExecState* exec, JSObject*, JSV
buffer[i] = toASCIILower(c);
}
if (!(ored & ~0x7f))
- return jsString(exec, UString::createNonCopying(buffer.releaseBuffer(), sSize));
+ return jsString(exec, UString::adopt(buffer));
bool error;
int length = Unicode::toLower(buffer.data(), sSize, sData, sSize, &error);
@@ -732,9 +731,12 @@ JSValue JSC_HOST_CALL stringProtoFuncToLowerCase(ExecState* exec, JSObject*, JSV
if (error)
return sVal;
}
- if (length == sSize && memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0)
- return sVal;
- return jsString(exec, UString::createNonCopying(buffer.releaseBuffer(), length));
+ if (length == sSize) {
+ if (memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0)
+ return sVal;
+ } else
+ buffer.resize(length);
+ return jsString(exec, UString::adopt(buffer));
}
JSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
@@ -756,7 +758,7 @@ JSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState* exec, JSObject*, JSV
buffer[i] = toASCIIUpper(c);
}
if (!(ored & ~0x7f))
- return jsString(exec, UString::createNonCopying(buffer.releaseBuffer(), sSize));
+ return jsString(exec, UString::adopt(buffer));
bool error;
int length = Unicode::toUpper(buffer.data(), sSize, sData, sSize, &error);
@@ -766,9 +768,12 @@ JSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState* exec, JSObject*, JSV
if (error)
return sVal;
}
- if (length == sSize && memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0)
- return sVal;
- return jsString(exec, UString::createNonCopying(buffer.releaseBuffer(), length));
+ if (length == sSize) {
+ if (memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0)
+ return sVal;
+ } else
+ buffer.resize(length);
+ return jsString(exec, UString::adopt(buffer));
}
JSValue JSC_HOST_CALL stringProtoFuncLocaleCompare(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
@@ -852,7 +857,8 @@ JSValue JSC_HOST_CALL stringProtoFuncFontsize(ExecState* exec, JSObject*, JSValu
unsigned stringSize = s.size();
unsigned bufferSize = 22 + stringSize;
UChar* buffer;
- if (!tryFastMalloc(bufferSize * sizeof(UChar)).getValue(buffer))
+ PassRefPtr<UStringImpl> impl = UStringImpl::tryCreateUninitialized(bufferSize, buffer);
+ if (!impl)
return jsUndefined();
buffer[0] = '<';
buffer[1] = 'f';
@@ -877,7 +883,7 @@ JSValue JSC_HOST_CALL stringProtoFuncFontsize(ExecState* exec, JSObject*, JSValu
buffer[19 + stringSize] = 'n';
buffer[20 + stringSize] = 't';
buffer[21 + stringSize] = '>';
- return jsNontrivialString(exec, UString::createNonCopying(buffer, bufferSize));
+ return jsNontrivialString(exec, impl);
}
return jsNontrivialString(exec, makeString("<font size=\"", a0.toString(exec), "\">", s, "</font>"));
@@ -900,7 +906,8 @@ JSValue JSC_HOST_CALL stringProtoFuncLink(ExecState* exec, JSObject*, JSValue th
unsigned stringSize = s.size();
unsigned bufferSize = 15 + linkTextSize + stringSize;
UChar* buffer;
- if (!tryFastMalloc(bufferSize * sizeof(UChar)).getValue(buffer))
+ PassRefPtr<UStringImpl> impl = UStringImpl::tryCreateUninitialized(bufferSize, buffer);
+ if (!impl)
return jsUndefined();
buffer[0] = '<';
buffer[1] = 'a';
@@ -919,7 +926,7 @@ JSValue JSC_HOST_CALL stringProtoFuncLink(ExecState* exec, JSObject*, JSValue th
buffer[12 + linkTextSize + stringSize] = '/';
buffer[13 + linkTextSize + stringSize] = 'a';
buffer[14 + linkTextSize + stringSize] = '>';
- return jsNontrivialString(exec, UString::createNonCopying(buffer, bufferSize));
+ return jsNontrivialString(exec, impl);
}
enum {
diff --git a/JavaScriptCore/runtime/Structure.cpp b/JavaScriptCore/runtime/Structure.cpp
index c370383..2c577dc 100644
--- a/JavaScriptCore/runtime/Structure.cpp
+++ b/JavaScriptCore/runtime/Structure.cpp
@@ -303,7 +303,7 @@ void Structure::despecifyDictionaryFunction(const Identifier& propertyName)
ASSERT(isDictionary());
ASSERT(m_propertyTable);
- unsigned i = rep->computedHash();
+ unsigned i = rep->existingHash();
#if DUMP_PROPERTYMAP_STATS
++numProbes;
@@ -321,7 +321,7 @@ void Structure::despecifyDictionaryFunction(const Identifier& propertyName)
++numCollisions;
#endif
- unsigned k = 1 | doubleHash(rep->computedHash());
+ unsigned k = 1 | doubleHash(rep->existingHash());
while (1) {
i += k;
@@ -686,7 +686,7 @@ size_t Structure::get(const UString::Rep* rep, unsigned& attributes, JSCell*& sp
if (!m_propertyTable)
return notFound;
- unsigned i = rep->computedHash();
+ unsigned i = rep->existingHash();
#if DUMP_PROPERTYMAP_STATS
++numProbes;
@@ -706,7 +706,7 @@ size_t Structure::get(const UString::Rep* rep, unsigned& attributes, JSCell*& sp
++numCollisions;
#endif
- unsigned k = 1 | doubleHash(rep->computedHash());
+ unsigned k = 1 | doubleHash(rep->existingHash());
while (1) {
i += k;
@@ -737,7 +737,7 @@ bool Structure::despecifyFunction(const Identifier& propertyName)
UString::Rep* rep = propertyName._ustring.rep();
- unsigned i = rep->computedHash();
+ unsigned i = rep->existingHash();
#if DUMP_PROPERTYMAP_STATS
++numProbes;
@@ -757,7 +757,7 @@ bool Structure::despecifyFunction(const Identifier& propertyName)
++numCollisions;
#endif
- unsigned k = 1 | doubleHash(rep->computedHash());
+ unsigned k = 1 | doubleHash(rep->existingHash());
while (1) {
i += k;
@@ -806,7 +806,7 @@ size_t Structure::put(const Identifier& propertyName, unsigned attributes, JSCel
// FIXME: Consider a fast case for tables with no deleted sentinels.
- unsigned i = rep->computedHash();
+ unsigned i = rep->existingHash();
unsigned k = 0;
bool foundDeletedElement = false;
unsigned deletedElementIndex = 0; // initialize to make the compiler happy
@@ -829,7 +829,7 @@ size_t Structure::put(const Identifier& propertyName, unsigned attributes, JSCel
}
if (k == 0) {
- k = 1 | doubleHash(rep->computedHash());
+ k = 1 | doubleHash(rep->existingHash());
#if DUMP_PROPERTYMAP_STATS
++numCollisions;
#endif
@@ -909,7 +909,7 @@ size_t Structure::remove(const Identifier& propertyName)
#endif
// Find the thing to remove.
- unsigned i = rep->computedHash();
+ unsigned i = rep->existingHash();
unsigned k = 0;
unsigned entryIndex;
UString::Rep* key = 0;
@@ -923,7 +923,7 @@ size_t Structure::remove(const Identifier& propertyName)
break;
if (k == 0) {
- k = 1 | doubleHash(rep->computedHash());
+ k = 1 | doubleHash(rep->existingHash());
#if DUMP_PROPERTYMAP_STATS
++numCollisions;
#endif
@@ -967,7 +967,7 @@ void Structure::insertIntoPropertyMapHashTable(const PropertyMapEntry& entry)
{
ASSERT(m_propertyTable);
- unsigned i = entry.key->computedHash();
+ unsigned i = entry.key->existingHash();
unsigned k = 0;
#if DUMP_PROPERTYMAP_STATS
@@ -980,7 +980,7 @@ void Structure::insertIntoPropertyMapHashTable(const PropertyMapEntry& entry)
break;
if (k == 0) {
- k = 1 | doubleHash(entry.key->computedHash());
+ k = 1 | doubleHash(entry.key->existingHash());
#if DUMP_PROPERTYMAP_STATS
++numCollisions;
#endif
@@ -1178,7 +1178,7 @@ void Structure::checkConsistency()
if (!rep)
continue;
++nonEmptyEntryCount;
- unsigned i = rep->computedHash();
+ unsigned i = rep->existingHash();
unsigned k = 0;
unsigned entryIndex;
while (1) {
@@ -1187,7 +1187,7 @@ void Structure::checkConsistency()
if (rep == m_propertyTable->entries()[entryIndex - 1].key)
break;
if (k == 0)
- k = 1 | doubleHash(rep->computedHash());
+ k = 1 | doubleHash(rep->existingHash());
i += k;
}
ASSERT(entryIndex == c + 1);
diff --git a/JavaScriptCore/runtime/Structure.h b/JavaScriptCore/runtime/Structure.h
index 099da6e..4cbe6ff 100644
--- a/JavaScriptCore/runtime/Structure.h
+++ b/JavaScriptCore/runtime/Structure.h
@@ -233,7 +233,7 @@ namespace JSC {
UString::Rep* rep = propertyName._ustring.rep();
- unsigned i = rep->computedHash();
+ unsigned i = rep->existingHash();
#if DUMP_PROPERTYMAP_STATS
++numProbes;
@@ -250,7 +250,7 @@ namespace JSC {
++numCollisions;
#endif
- unsigned k = 1 | WTF::doubleHash(rep->computedHash());
+ unsigned k = 1 | WTF::doubleHash(rep->existingHash());
while (1) {
i += k;
diff --git a/JavaScriptCore/runtime/StructureTransitionTable.h b/JavaScriptCore/runtime/StructureTransitionTable.h
index 0fa7b73..35fb7e4 100644
--- a/JavaScriptCore/runtime/StructureTransitionTable.h
+++ b/JavaScriptCore/runtime/StructureTransitionTable.h
@@ -42,7 +42,7 @@ namespace JSC {
typedef std::pair<RefPtr<UString::Rep>, unsigned> Key;
static unsigned hash(const Key& p)
{
- return p.first->computedHash();
+ return p.first->existingHash();
}
static bool equal(const Key& a, const Key& b)
diff --git a/JavaScriptCore/runtime/UString.cpp b/JavaScriptCore/runtime/UString.cpp
index cb3803f..e75a05c 100644
--- a/JavaScriptCore/runtime/UString.cpp
+++ b/JavaScriptCore/runtime/UString.cpp
@@ -170,7 +170,7 @@ static PassRefPtr<UString::Rep> createRep(const char* c)
size_t length = strlen(c);
UChar* d;
- PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, d);
+ PassRefPtr<UStringImpl> result = UStringImpl::tryCreateUninitialized(length, d);
if (!result)
return &UString::Rep::null();
@@ -188,7 +188,7 @@ static inline PassRefPtr<UString::Rep> createRep(const char* c, int length)
return &UString::Rep::empty();
UChar* d;
- PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, d);
+ PassRefPtr<UStringImpl> result = UStringImpl::tryCreateUninitialized(length, d);
if (!result)
return &UString::Rep::null();
@@ -212,15 +212,7 @@ UString::UString(const UChar* c, int length)
if (length == 0)
m_rep = &Rep::empty();
else
- m_rep = Rep::createCopying(c, length);
-}
-
-UString UString::createNonCopying(UChar* c, int length)
-{
- if (length == 0)
- return UString(&Rep::empty());
- else
- return Rep::create(c, length);
+ m_rep = Rep::create(c, length);
}
UString UString::createFromUTF8(const char* string)
@@ -237,19 +229,6 @@ UString UString::createFromUTF8(const char* string)
return UString(buffer.data(), p - buffer.data());
}
-UString UString::createUninitialized(unsigned length, UChar*& output)
-{
- if (!length) {
- output = &sharedEmptyChar;
- return UString(&Rep::empty());
- }
-
- if (PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, output))
- return result;
- output = 0;
- return UString();
-}
-
UString UString::from(int i)
{
UChar buf[1 + sizeof(i) * 3];
@@ -390,7 +369,8 @@ UString UString::spliceSubstringsWithSeparators(const Range* substringRanges, in
return "";
UChar* buffer;
- if (!UStringImpl::allocChars(totalLength).getValue(buffer))
+ PassRefPtr<Rep> rep = Rep::tryCreateUninitialized(totalLength, buffer);
+ if (!rep)
return null();
int maxCount = max(rangeCount, separatorCount);
@@ -406,7 +386,7 @@ UString UString::spliceSubstringsWithSeparators(const Range* substringRanges, in
}
}
- return UString::Rep::create(buffer, totalLength);
+ return rep;
}
UString UString::replaceRange(int rangeStart, int rangeLength, const UString& replacement) const
@@ -419,7 +399,8 @@ UString UString::replaceRange(int rangeStart, int rangeLength, const UString& re
return "";
UChar* buffer;
- if (!UStringImpl::allocChars(totalLength).getValue(buffer))
+ PassRefPtr<Rep> rep = Rep::tryCreateUninitialized(totalLength, buffer);
+ if (!rep)
return null();
UStringImpl::copyChars(buffer, data(), rangeStart);
@@ -427,7 +408,7 @@ UString UString::replaceRange(int rangeStart, int rangeLength, const UString& re
int rangeEnd = rangeStart + rangeLength;
UStringImpl::copyChars(buffer + rangeStart + replacementLength, data() + rangeEnd, size() - rangeEnd);
- return UString::Rep::create(buffer, totalLength);
+ return rep;
}
bool UString::getCString(CStringBuffer& buffer) const
@@ -488,14 +469,13 @@ UString& UString::operator=(const char* c)
}
int l = static_cast<int>(strlen(c));
- UChar* d;
- if (!UStringImpl::allocChars(l).getValue(d)) {
+ UChar* d = 0;
+ m_rep = Rep::tryCreateUninitialized(l, d);
+ if (m_rep) {
+ for (int i = 0; i < l; i++)
+ d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
+ } else
makeNull();
- return *this;
- }
- for (int i = 0; i < l; i++)
- d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
- m_rep = Rep::create(d, l);
return *this;
}
diff --git a/JavaScriptCore/runtime/UString.h b/JavaScriptCore/runtime/UString.h
index 0f63c36..59e296f 100644
--- a/JavaScriptCore/runtime/UString.h
+++ b/JavaScriptCore/runtime/UString.h
@@ -103,9 +103,13 @@ namespace JSC {
{
}
- static UString createNonCopying(UChar* c, int length);
+ template<size_t inlineCapacity>
+ static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector)
+ {
+ return Rep::adopt(vector);
+ }
+
static UString createFromUTF8(const char*);
- static UString createUninitialized(unsigned length, UChar*& output);
static UString from(int);
static UString from(long long);
@@ -273,8 +277,8 @@ namespace JSC {
static const int minShareSize = Heap::minExtraCost / sizeof(UChar);
struct IdentifierRepHash : PtrHash<RefPtr<JSC::UString::Rep> > {
- static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->computedHash(); }
- static unsigned hash(JSC::UString::Rep* key) { return key->computedHash(); }
+ static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->existingHash(); }
+ static unsigned hash(JSC::UString::Rep* key) { return key->existingHash(); }
};
void initializeUString();
@@ -357,8 +361,8 @@ namespace JSC {
UChar* buffer;
unsigned length = adapter1.length() + adapter2.length();
- UString resultString = UString::createUninitialized(length, buffer);
- if (!buffer)
+ PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
+ if (!resultImpl)
return UString();
UChar* result = buffer;
@@ -366,7 +370,7 @@ namespace JSC {
result += adapter1.length();
adapter2.writeTo(result);
- return resultString;
+ return resultImpl;
}
template<typename StringType1, typename StringType2, typename StringType3>
@@ -378,8 +382,8 @@ namespace JSC {
UChar* buffer;
unsigned length = adapter1.length() + adapter2.length() + adapter3.length();
- UString resultString = UString::createUninitialized(length, buffer);
- if (!buffer)
+ PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
+ if (!resultImpl)
return UString();
UChar* result = buffer;
@@ -389,7 +393,7 @@ namespace JSC {
result += adapter2.length();
adapter3.writeTo(result);
- return resultString;
+ return resultImpl;
}
template<typename StringType1, typename StringType2, typename StringType3, typename StringType4>
@@ -402,8 +406,8 @@ namespace JSC {
UChar* buffer;
unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length();
- UString resultString = UString::createUninitialized(length, buffer);
- if (!buffer)
+ PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
+ if (!resultImpl)
return UString();
UChar* result = buffer;
@@ -415,7 +419,7 @@ namespace JSC {
result += adapter3.length();
adapter4.writeTo(result);
- return resultString;
+ return resultImpl;
}
template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5>
@@ -429,8 +433,8 @@ namespace JSC {
UChar* buffer;
unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length();
- UString resultString = UString::createUninitialized(length, buffer);
- if (!buffer)
+ PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
+ if (!resultImpl)
return UString();
UChar* result = buffer;
@@ -444,7 +448,7 @@ namespace JSC {
result += adapter4.length();
adapter5.writeTo(result);
- return resultString;
+ return resultImpl;
}
template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6>
@@ -459,8 +463,8 @@ namespace JSC {
UChar* buffer;
unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length() + adapter6.length();
- UString resultString = UString::createUninitialized(length, buffer);
- if (!buffer)
+ PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
+ if (!resultImpl)
return UString();
UChar* result = buffer;
@@ -476,7 +480,7 @@ namespace JSC {
result += adapter5.length();
adapter6.writeTo(result);
- return resultString;
+ return resultImpl;
}
template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7>
@@ -492,8 +496,8 @@ namespace JSC {
UChar* buffer;
unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length() + adapter6.length() + adapter7.length();
- UString resultString = UString::createUninitialized(length, buffer);
- if (!buffer)
+ PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
+ if (!resultImpl)
return UString();
UChar* result = buffer;
@@ -511,7 +515,7 @@ namespace JSC {
result += adapter6.length();
adapter7.writeTo(result);
- return resultString;
+ return resultImpl;
}
template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7, typename StringType8>
@@ -528,8 +532,8 @@ namespace JSC {
UChar* buffer;
unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length() + adapter6.length() + adapter7.length() + adapter8.length();
- UString resultString = UString::createUninitialized(length, buffer);
- if (!buffer)
+ PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
+ if (!resultImpl)
return UString();
UChar* result = buffer;
@@ -549,7 +553,7 @@ namespace JSC {
result += adapter7.length();
adapter8.writeTo(result);
- return resultString;
+ return resultImpl;
}
} // namespace JSC
diff --git a/JavaScriptCore/runtime/UStringImpl.h b/JavaScriptCore/runtime/UStringImpl.h
index 05b75cb..15e56a8 100644
--- a/JavaScriptCore/runtime/UStringImpl.h
+++ b/JavaScriptCore/runtime/UStringImpl.h
@@ -31,6 +31,7 @@
#include <wtf/OwnFastMallocPtr.h>
#include <wtf/PossiblyNull.h>
#include <wtf/StringHashFunctions.h>
+#include <wtf/Vector.h>
#include <wtf/unicode/Unicode.h>
namespace JSC {
@@ -83,12 +84,15 @@ private:
class UStringImpl : Noncopyable {
public:
- static PassRefPtr<UStringImpl> create(UChar* buffer, int length)
+ template<size_t inlineCapacity>
+ static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector)
{
- return adoptRef(new UStringImpl(buffer, length, BufferOwned));
+ if (unsigned length = vector.size())
+ return adoptRef(new UStringImpl(vector.releaseBuffer(), length, BufferOwned));
+ return &empty();
}
- static PassRefPtr<UStringImpl> createCopying(const UChar* buffer, int length)
+ static PassRefPtr<UStringImpl> create(const UChar* buffer, int length)
{
UChar* newBuffer;
if (!UStringImpl::allocChars(length).getValue(newBuffer))
@@ -111,14 +115,30 @@ public:
static PassRefPtr<UStringImpl> createUninitialized(unsigned length, UChar*& output)
{
- ASSERT(length);
+ if (!length) {
+ output = 0;
+ return &empty();
+ }
+
if (length > ((std::numeric_limits<size_t>::max() - sizeof(UStringImpl)) / sizeof(UChar)))
- return 0;
+ CRASH();
+ UStringImpl* resultImpl = static_cast<UStringImpl*>(fastMalloc(sizeof(UChar) * length + sizeof(UStringImpl)));
+ output = reinterpret_cast<UChar*>(resultImpl + 1);
+ return adoptRef(new(resultImpl) UStringImpl(output, length, BufferInternal));
+ }
+ static PassRefPtr<UStringImpl> tryCreateUninitialized(unsigned length, UChar*& output)
+ {
+ if (!length) {
+ output = 0;
+ return &empty();
+ }
+
+ if (length > ((std::numeric_limits<size_t>::max() - sizeof(UStringImpl)) / sizeof(UChar)))
+ return 0;
UStringImpl* resultImpl;
if (!tryFastMalloc(sizeof(UChar) * length + sizeof(UStringImpl)).getValue(resultImpl))
return 0;
-
output = reinterpret_cast<UChar*>(resultImpl + 1);
return adoptRef(new(resultImpl) UStringImpl(output, length, BufferInternal));
}
@@ -138,7 +158,7 @@ public:
return m_length;
}
unsigned hash() const { if (!m_hash) m_hash = computeHash(data(), m_length); return m_hash; }
- unsigned computedHash() const { ASSERT(m_hash); return m_hash; } // fast path for Identifiers
+ unsigned existingHash() const { ASSERT(m_hash); return m_hash; } // fast path for Identifiers
void setHash(unsigned hash) { ASSERT(hash == computeHash(data(), m_length)); m_hash = hash; } // fast path for Identifiers
bool isIdentifier() const { return m_isIdentifier; }
void setIsIdentifier(bool isIdentifier) { m_isIdentifier = isIdentifier; }
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 6ed7bc1..e31ed6b 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,16 @@
+2010-01-14 Gavin Barraclough <barraclough at apple.com>
+
+ Rubber stamped by Sam Weinig.
+
+ Make naming & behaviour of UString[Impl] methods more consistent.
+ https://bugs.webkit.org/show_bug.cgi?id=33702
+
+ WebCore change reflecting UString method name change computedHash() -> existingHash().
+
+ * platform/text/AtomicString.cpp:
+ (WebCore::AtomicString::add):
+ (WebCore::AtomicString::find):
+
2010-01-14 Dan Bernstein <mitz at apple.com>
Reviewed by Simon Fraser.
diff --git a/WebCore/platform/text/AtomicString.cpp b/WebCore/platform/text/AtomicString.cpp
index e35627c..e2ff2b4 100644
--- a/WebCore/platform/text/AtomicString.cpp
+++ b/WebCore/platform/text/AtomicString.cpp
@@ -252,7 +252,7 @@ PassRefPtr<StringImpl> AtomicString::add(const JSC::Identifier& identifier)
if (!length)
return StringImpl::empty();
- HashAndCharacters buffer = { string->computedHash(), string->data(), length };
+ HashAndCharacters buffer = { string->existingHash(), string->data(), length };
pair<HashSet<StringImpl*>::iterator, bool> addResult = stringTable().add<HashAndCharacters, HashAndCharactersTranslator>(buffer);
if (!addResult.second)
return *addResult.first;
@@ -286,7 +286,7 @@ AtomicStringImpl* AtomicString::find(const JSC::Identifier& identifier)
if (!length)
return static_cast<AtomicStringImpl*>(StringImpl::empty());
- HashAndCharacters buffer = { string->computedHash(), string->data(), length };
+ HashAndCharacters buffer = { string->existingHash(), string->data(), length };
HashSet<StringImpl*>::iterator iterator = stringTable().find<HashAndCharacters, HashAndCharactersTranslator>(buffer);
if (iterator == stringTable().end())
return 0;
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list