Title: [121377] trunk/Source/WebCore
- Revision
- 121377
- Author
- commit-qu...@webkit.org
- Date
- 2012-06-27 15:13:53 -0700 (Wed, 27 Jun 2012)
Log Message
IndexedDB: make IDBKey immutable
https://bugs.webkit.org/show_bug.cgi?id=90016
Patch by Alec Flett <alecfl...@chromium.org> on 2012-06-27
Reviewed by Tony Chang.
Make all members of IDBKey const, so that this can be considered
an immutable, and thus safe to copy and/or stop ref-counting.
No new tests, existing tests show this works.
* Modules/indexeddb/IDBKey.cpp:
(WebCore::IDBKey::compare):
* Modules/indexeddb/IDBKey.h:
(WebCore::IDBKey::createInvalid):
(WebCore::IDBKey::createNumber):
(WebCore::IDBKey::createString):
(WebCore::IDBKey::createDate):
(WebCore::IDBKey::createMultiEntryArray):
(WebCore::IDBKey::createArray):
(WebCore::IDBKey::date):
(WebCore::IDBKey::IDBKey):
(IDBKey):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (121376 => 121377)
--- trunk/Source/WebCore/ChangeLog 2012-06-27 22:00:55 UTC (rev 121376)
+++ trunk/Source/WebCore/ChangeLog 2012-06-27 22:13:53 UTC (rev 121377)
@@ -1,3 +1,28 @@
+2012-06-27 Alec Flett <alecfl...@chromium.org>
+
+ IndexedDB: make IDBKey immutable
+ https://bugs.webkit.org/show_bug.cgi?id=90016
+
+ Reviewed by Tony Chang.
+
+ Make all members of IDBKey const, so that this can be considered
+ an immutable, and thus safe to copy and/or stop ref-counting.
+
+ No new tests, existing tests show this works.
+
+ * Modules/indexeddb/IDBKey.cpp:
+ (WebCore::IDBKey::compare):
+ * Modules/indexeddb/IDBKey.h:
+ (WebCore::IDBKey::createInvalid):
+ (WebCore::IDBKey::createNumber):
+ (WebCore::IDBKey::createString):
+ (WebCore::IDBKey::createDate):
+ (WebCore::IDBKey::createMultiEntryArray):
+ (WebCore::IDBKey::createArray):
+ (WebCore::IDBKey::date):
+ (WebCore::IDBKey::IDBKey):
+ (IDBKey):
+
2012-06-27 Erik Arvidsson <a...@chromium.org>
[V8] Improve variable resolution order on window
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKey.cpp (121376 => 121377)
--- trunk/Source/WebCore/Modules/indexeddb/IDBKey.cpp 2012-06-27 22:00:55 UTC (rev 121376)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKey.cpp 2012-06-27 22:13:53 UTC (rev 121377)
@@ -30,12 +30,6 @@
namespace WebCore {
-IDBKey::IDBKey()
- : m_type(InvalidType)
- , m_sizeEstimate(kOverheadSize)
-{
-}
-
IDBKey::~IDBKey()
{
}
@@ -75,8 +69,6 @@
case StringType:
return -codePointCompare(other->m_string, m_string);
case DateType:
- return (m_date < other->m_date) ? -1 :
- (m_date > other->m_date) ? 1 : 0;
case NumberType:
return (m_number < other->m_number) ? -1 :
(m_number > other-> m_number) ? 1 : 0;
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKey.h (121376 => 121377)
--- trunk/Source/WebCore/Modules/indexeddb/IDBKey.h 2012-06-27 22:00:55 UTC (rev 121376)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKey.h 2012-06-27 22:13:53 UTC (rev 121377)
@@ -41,44 +41,29 @@
static PassRefPtr<IDBKey> createInvalid()
{
- RefPtr<IDBKey> idbKey = adoptRef(new IDBKey());
- idbKey->m_type = InvalidType;
- return idbKey.release();
+ return adoptRef(new IDBKey());
}
static PassRefPtr<IDBKey> createNumber(double number)
{
- RefPtr<IDBKey> idbKey = adoptRef(new IDBKey());
- idbKey->m_type = NumberType;
- idbKey->m_number = number;
- idbKey->m_sizeEstimate += sizeof(double);
- return idbKey.release();
+ return adoptRef(new IDBKey(NumberType, number));
}
static PassRefPtr<IDBKey> createString(const String& string)
{
- RefPtr<IDBKey> idbKey = adoptRef(new IDBKey());
- idbKey->m_type = StringType;
- idbKey->m_string = string;
- idbKey->m_sizeEstimate += string.length() * sizeof(UChar);
- return idbKey.release();
+ return adoptRef(new IDBKey(string));
}
static PassRefPtr<IDBKey> createDate(double date)
{
- RefPtr<IDBKey> idbKey = adoptRef(new IDBKey());
- idbKey->m_type = DateType;
- idbKey->m_date = date;
- idbKey->m_sizeEstimate += sizeof(double);
- return idbKey.release();
+ return adoptRef(new IDBKey(DateType, date));
}
static PassRefPtr<IDBKey> createMultiEntryArray(const KeyArray& array)
{
- RefPtr<IDBKey> idbKey = adoptRef(new IDBKey());
- idbKey->m_type = ArrayType;
- KeyArray& result = idbKey->m_array;
+ KeyArray result;
+ size_t sizeEstimate = 0;
for (size_t i = 0; i < array.size(); i++) {
if (!array[i]->isValid())
continue;
@@ -92,23 +77,21 @@
}
if (!skip) {
result.append(array[i]);
- idbKey->m_sizeEstimate += array[i]->m_sizeEstimate;
+ sizeEstimate += array[i]->m_sizeEstimate;
}
}
+ RefPtr<IDBKey> idbKey = adoptRef(new IDBKey(result, sizeEstimate));
ASSERT(idbKey->isValid());
return idbKey.release();
}
static PassRefPtr<IDBKey> createArray(const KeyArray& array)
{
- RefPtr<IDBKey> idbKey = adoptRef(new IDBKey());
- idbKey->m_type = ArrayType;
- idbKey->m_array = array;
-
+ size_t sizeEstimate = 0;
for (size_t i = 0; i < array.size(); ++i)
- idbKey->m_sizeEstimate += array[i]->m_sizeEstimate;
+ sizeEstimate += array[i]->m_sizeEstimate;
- return idbKey.release();
+ return adoptRef(new IDBKey(array, sizeEstimate));
}
~IDBKey();
@@ -141,7 +124,7 @@
double date() const
{
ASSERT(m_type == DateType);
- return m_date;
+ return m_number;
}
double number() const
@@ -165,15 +148,17 @@
using ThreadSafeRefCounted<IDBKey>::deref;
private:
- IDBKey();
+ IDBKey() : m_type(InvalidType), m_number(0), m_sizeEstimate(kOverheadSize) { }
+ IDBKey(Type type, double number) : m_type(type), m_number(number), m_sizeEstimate(kOverheadSize + sizeof(double)) { }
+ explicit IDBKey(const String& value) : m_type(StringType), m_string(value), m_number(0), m_sizeEstimate(kOverheadSize + value.length() * sizeof(UChar)) { }
+ IDBKey(const KeyArray& keyArray, size_t arraySize) : m_type(ArrayType), m_array(keyArray), m_number(0), m_sizeEstimate(kOverheadSize + arraySize) { }
- Type m_type;
- KeyArray m_array;
- String m_string;
- double m_date;
- double m_number;
+ const Type m_type;
+ const KeyArray m_array;
+ const String m_string;
+ const double m_number;
- size_t m_sizeEstimate;
+ const size_t m_sizeEstimate;
// Very rough estimate of minimum key size overhead.
enum { kOverheadSize = 16 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes