Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Unified Diff: third_party/WebKit/Source/wtf/text/StringImpl.cpp

Issue 2624443003: Enable ThreadRestrictionVerifier for StringImpl (Closed)
Patch Set: static assert Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/text/StringImpl.cpp
diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.cpp b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
index 641fbc9c72c4b7aeecf2ff0d48498bb7d27e2e20..f8b6b7b033bb9be1e02e8ffbe480421656638a98 100644
--- a/third_party/WebKit/Source/wtf/text/StringImpl.cpp
+++ b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
@@ -32,6 +32,7 @@
#include "wtf/allocator/Partitions.h"
#include "wtf/text/AtomicString.h"
#include "wtf/text/AtomicStringTable.h"
+#include "wtf/text/CString.h"
#include "wtf/text/CharacterNames.h"
#include "wtf/text/StringBuffer.h"
#include "wtf/text/StringHash.h"
@@ -54,8 +55,16 @@ namespace WTF {
using namespace Unicode;
-static_assert(sizeof(StringImpl) == 3 * sizeof(int),
+// As of Jan 2017, StringImpl needs 2 * sizeof(int) + 29 bits of data, and
+// sizeof(ThreadRestrictionVerifier) is 16 bytes. Thus, in DCHECK mode the
+// class may be padded to 32 bytes.
+#if DCHECK_IS_ON()
+static_assert(sizeof(StringImpl) <= 8 * sizeof(int),
+ "StringImpl should stay small");
+#else
+static_assert(sizeof(StringImpl) <= 3 * sizeof(int),
"StringImpl should stay small");
+#endif
#ifdef STRING_STATS
@@ -300,7 +309,7 @@ inline StringImpl::~StringImpl() {
AtomicStringTable::instance().remove(this);
}
-void StringImpl::destroyIfNotStatic() {
+void StringImpl::destroyIfNotStatic() const {
if (!isStatic())
delete this;
}
@@ -324,6 +333,13 @@ bool StringImpl::isSafeToSendToAnotherThread() const {
return false;
}
+#if DCHECK_IS_ON()
+std::string StringImpl::asciiForDebugging() const {
+ CString ascii = String(substring(0, 128)).ascii();
+ return std::string(ascii.data(), ascii.length());
+}
+#endif
+
PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length,
LChar*& data) {
if (!length) {
@@ -501,13 +517,16 @@ bool StringImpl::containsOnlyWhitespace() {
return true;
}
-PassRefPtr<StringImpl> StringImpl::substring(unsigned start, unsigned length) {
+PassRefPtr<StringImpl> StringImpl::substring(unsigned start,
+ unsigned length) const {
if (start >= m_length)
return empty();
unsigned maxLength = m_length - start;
if (length >= maxLength) {
+ // PassRefPtr has trouble dealing with const arguments. It should be updated
+ // so this const_cast is not necessary.
if (!start)
- return this;
+ return const_cast<StringImpl*>(this);
length = maxLength;
}
if (is8Bit())
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.h ('k') | third_party/WebKit/Source/wtf/text/StringImplTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698