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

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

Issue 2624443003: Enable ThreadRestrictionVerifier for StringImpl (Closed)
Patch Set: minimal const peppering 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..20b378b6da0dcdccbacf8cab655c1ecd49a37d02 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,10 @@ namespace WTF {
using namespace Unicode;
+#if !DCHECK_IS_ON()
esprehn 2017/01/13 22:35:29 I'd prefer we changed this to have a side for DCHE
static_assert(sizeof(StringImpl) == 3 * sizeof(int),
"StringImpl should stay small");
+#endif
#ifdef STRING_STATS
@@ -300,7 +303,7 @@ inline StringImpl::~StringImpl() {
AtomicStringTable::instance().remove(this);
}
-void StringImpl::destroyIfNotStatic() {
+void StringImpl::destroyIfNotStatic() const {
if (!isStatic())
delete this;
}
@@ -324,6 +327,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 +511,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