Diff
Modified: branches/safari-604.5.100-branch/Source/_javascript_Core/ChangeLog (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/_javascript_Core/ChangeLog 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/_javascript_Core/ChangeLog 2017-12-19 23:00:51 UTC (rev 226144)
@@ -1,3 +1,26 @@
+2017-12-18 Jason Marcell <[email protected]>
+
+ Cherry-pick r226068. rdar://problem/36112028
+
+ 2017-12-16 Filip Pizlo <[email protected]>
+
+ Vector index masking
+ https://bugs.webkit.org/show_bug.cgi?id=180909
+
+ Reviewed by Keith Miller.
+
+ Adopt index masking for strings.
+
+ * dfg/DFGSpeculativeJIT.cpp:
+ (JSC::DFG::SpeculativeJIT::compileGetCharCodeAt):
+ (JSC::DFG::SpeculativeJIT::compileGetByValOnString):
+ * ftl/FTLAbstractHeapRepository.h:
+ * ftl/FTLLowerDFGToB3.cpp:
+ (JSC::FTL::DFG::LowerDFGToB3::compileStringCharAt):
+ (JSC::FTL::DFG::LowerDFGToB3::compileStringCharCodeAt):
+ * jit/ThunkGenerators.cpp:
+ (JSC::stringCharLoad):
+
2017-12-04 Jason Marcell <[email protected]>
Cherry-pick r225273. rdar://problem/35838163
Modified: branches/safari-604.5.100-branch/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp 2017-12-19 23:00:51 UTC (rev 226144)
@@ -1994,6 +1994,7 @@
GPRReg scratchReg = scratch.gpr();
m_jit.loadPtr(MacroAssembler::Address(stringReg, JSString::offsetOfValue()), scratchReg);
+ m_jit.and32(MacroAssembler::Address(scratchReg, StringImpl::maskOffset()), indexReg);
// Load the character into scratchReg
JITCompiler::Jump is16Bit = m_jit.branchTest32(MacroAssembler::Zero, MacroAssembler::Address(scratchReg, StringImpl::flagsOffset()), TrustedImm32(StringImpl::flagIs8Bit()));
@@ -2041,6 +2042,7 @@
speculationCheck(OutOfBounds, JSValueRegs(), 0, outOfBounds);
m_jit.loadPtr(MacroAssembler::Address(baseReg, JSString::offsetOfValue()), scratchReg);
+ m_jit.and32(MacroAssembler::Address(scratchReg, StringImpl::maskOffset()), propertyReg);
// Load the character into scratchReg
JITCompiler::Jump is16Bit = m_jit.branchTest32(MacroAssembler::Zero, MacroAssembler::Address(scratchReg, StringImpl::flagsOffset()), TrustedImm32(StringImpl::flagIs8Bit()));
Modified: branches/safari-604.5.100-branch/Source/_javascript_Core/ftl/FTLAbstractHeapRepository.h (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/_javascript_Core/ftl/FTLAbstractHeapRepository.h 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/_javascript_Core/ftl/FTLAbstractHeapRepository.h 2017-12-19 23:00:51 UTC (rev 226144)
@@ -105,6 +105,7 @@
macro(StringImpl_data, StringImpl::dataOffset()) \
macro(StringImpl_hashAndFlags, StringImpl::flagsOffset()) \
macro(StringImpl_length, StringImpl::lengthMemoryOffset()) \
+ macro(StringImpl_mask, StringImpl::maskOffset()) \
macro(Structure_classInfo, Structure::classInfoOffset()) \
macro(Structure_globalObject, Structure::globalObjectOffset()) \
macro(Structure_prototype, Structure::prototypeOffset()) \
Modified: branches/safari-604.5.100-branch/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp 2017-12-19 23:00:51 UTC (rev 226144)
@@ -5413,6 +5413,7 @@
LBasicBlock lastNext = m_out.appendTo(fastPath, slowPath);
LValue stringImpl = m_out.loadPtr(base, m_heaps.JSString_value);
+ LValue indexForAccess = m_out.bitAnd(index, m_out.load32(stringImpl, m_heaps.StringImpl_mask));
LBasicBlock is8Bit = m_out.newBlock();
LBasicBlock is16Bit = m_out.newBlock();
@@ -5429,7 +5430,7 @@
ValueFromBlock char8Bit = m_out.anchor(
m_out.load8ZeroExt32(m_out.baseIndex(
- m_heaps.characters8, storage, m_out.zeroExtPtr(index),
+ m_heaps.characters8, storage, m_out.zeroExtPtr(indexForAccess),
provenValue(m_node->child2()))));
m_out.jump(bitsContinuation);
@@ -5437,7 +5438,7 @@
LValue char16BitValue = m_out.load16ZeroExt32(
m_out.baseIndex(
- m_heaps.characters16, storage, m_out.zeroExtPtr(index),
+ m_heaps.characters16, storage, m_out.zeroExtPtr(indexForAccess),
provenValue(m_node->child2())));
ValueFromBlock char16Bit = m_out.anchor(char16BitValue);
m_out.branch(
@@ -5519,6 +5520,7 @@
index, m_out.load32NonNegative(base, m_heaps.JSString_length)));
LValue stringImpl = m_out.loadPtr(base, m_heaps.JSString_value);
+ LValue indexForAccess = m_out.bitAnd(index, m_out.load32(stringImpl, m_heaps.StringImpl_mask));
m_out.branch(
m_out.testIsZero32(
@@ -5530,7 +5532,7 @@
ValueFromBlock char8Bit = m_out.anchor(
m_out.load8ZeroExt32(m_out.baseIndex(
- m_heaps.characters8, storage, m_out.zeroExtPtr(index),
+ m_heaps.characters8, storage, m_out.zeroExtPtr(indexForAccess),
provenValue(m_node->child2()))));
m_out.jump(continuation);
@@ -5538,7 +5540,7 @@
ValueFromBlock char16Bit = m_out.anchor(
m_out.load16ZeroExt32(m_out.baseIndex(
- m_heaps.characters16, storage, m_out.zeroExtPtr(index),
+ m_heaps.characters16, storage, m_out.zeroExtPtr(indexForAccess),
provenValue(m_node->child2()))));
m_out.jump(continuation);
Modified: branches/safari-604.5.100-branch/Source/_javascript_Core/jit/ThunkGenerators.cpp (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/_javascript_Core/jit/ThunkGenerators.cpp 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/_javascript_Core/jit/ThunkGenerators.cpp 2017-12-19 23:00:51 UTC (rev 226144)
@@ -568,6 +568,7 @@
SpecializedThunkJIT::JumpList cont8Bit;
// Load the string flags
jit.loadPtr(MacroAssembler::Address(SpecializedThunkJIT::regT0, StringImpl::flagsOffset()), SpecializedThunkJIT::regT2);
+ jit.and32(MacroAssembler::Address(SpecializedThunkJIT::regT0, StringImpl::maskOffset()), SpecializedThunkJIT::regT1);
jit.loadPtr(MacroAssembler::Address(SpecializedThunkJIT::regT0, StringImpl::dataOffset()), SpecializedThunkJIT::regT0);
is16Bit.append(jit.branchTest32(MacroAssembler::Zero, SpecializedThunkJIT::regT2, MacroAssembler::TrustedImm32(StringImpl::flagIs8Bit())));
jit.load8(MacroAssembler::BaseIndex(SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1, MacroAssembler::TimesOne, 0), SpecializedThunkJIT::regT0);
Modified: branches/safari-604.5.100-branch/Source/WTF/ChangeLog (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/WTF/ChangeLog 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/WTF/ChangeLog 2017-12-19 23:00:51 UTC (rev 226144)
@@ -1,3 +1,61 @@
+2017-12-18 Jason Marcell <[email protected]>
+
+ Cherry-pick r226068. rdar://problem/36112028
+
+ 2017-12-16 Filip Pizlo <[email protected]>
+
+ Vector index masking
+ https://bugs.webkit.org/show_bug.cgi?id=180909
+
+ Reviewed by Keith Miller.
+
+ Adds index masking to StringImpl and Vector.
+
+ Perf:
+
+ - 0.4% slower on microbenchmarks.
+ - Octane totally even.
+ - Kraken may be 0.8% slower.
+ - Speedometer is 0.8% slower with p = 0.008.
+ - membuster is even:
+ - snap2pre: 0.7% bigger w/ p = 0.26,
+ - snap2post: 0.3% smaller w/ p = 0.81,
+ - snap3pre: 1.2% bigger w/ p = 0.63,
+ - snap3post: 0.4% smaller w/ p = 0.76.
+
+ * wtf/MathExtras.h:
+ (WTF::roundUpToPowerOfTwo):
+ (WTF::maskForSize):
+ * wtf/SizeLimits.cpp:
+ * wtf/Vector.h:
+ (WTF::VectorBufferBase::allocateBuffer):
+ (WTF::VectorBufferBase::tryAllocateBuffer):
+ (WTF::VectorBufferBase::reallocateBuffer):
+ (WTF::VectorBufferBase::deallocateBuffer):
+ (WTF::VectorBufferBase::releaseBuffer):
+ (WTF::VectorBufferBase::VectorBufferBase):
+ (WTF::VectorBufferBase::updateMask):
+ (WTF::VectorBuffer::allocateBuffer):
+ (WTF::VectorBuffer::tryAllocateBuffer):
+ (WTF::VectorBuffer::swap):
+ (WTF::VectorBuffer::restoreInlineBufferIfNeeded):
+ (WTF::Vector::at):
+ (WTF::Vector::at const):
+ * wtf/text/StringImpl.h:
+ (WTF::StringImpl::maskOffset):
+ (WTF::StringImpl::mask const):
+ (WTF::StringImplShape::StringImplShape):
+ (WTF::StringImpl::at const):
+ (WTF::StringImpl::tailOffset):
+ * wtf/text/StringView.h:
+ (WTF::StringView::StringView):
+ (WTF::StringView::operator=):
+ (WTF::StringView::initialize):
+ (WTF::StringView::clear):
+ (WTF::StringView::operator[] const):
+ * wtf/text/WTFString.h:
+ (WTF::String::mask const):
+
2017-10-18 Jason Marcell <[email protected]>
Cherry-pick r223315. rdar://problem/34985202
Modified: branches/safari-604.5.100-branch/Source/WTF/wtf/MathExtras.h (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/WTF/wtf/MathExtras.h 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/WTF/wtf/MathExtras.h 2017-12-19 23:00:51 UTC (rev 226144)
@@ -356,7 +356,7 @@
namespace WTF {
// From http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
-inline uint32_t roundUpToPowerOfTwo(uint32_t v)
+inline constexpr uint32_t roundUpToPowerOfTwo(uint32_t v)
{
v--;
v |= v >> 1;
@@ -368,6 +368,13 @@
return v;
}
+inline constexpr unsigned maskForSize(unsigned size)
+{
+ if (!size)
+ return 0;
+ return roundUpToPowerOfTwo(size) - 1;
+}
+
inline unsigned fastLog2(unsigned i)
{
unsigned log2 = 0;
Modified: branches/safari-604.5.100-branch/Source/WTF/wtf/SizeLimits.cpp (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/WTF/wtf/SizeLimits.cpp 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/WTF/wtf/SizeLimits.cpp 2017-12-19 23:00:51 UTC (rev 226144)
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -62,14 +63,22 @@
template<typename T>
struct SameSizeAsVectorWithInlineCapacity<T, 0> {
+ WTF_MAKE_NONCOPYABLE(SameSizeAsVectorWithInlineCapacity);
+public:
void* bufferPointer;
unsigned capacity;
unsigned size;
+ unsigned mask;
};
+template<typename T>
+struct SameSizeAsVectorWithInlineCapacityBase : SameSizeAsVectorWithInlineCapacity<T> {
+};
+
template<typename T, unsigned inlineCapacity>
-struct SameSizeAsVectorWithInlineCapacity {
- SameSizeAsVectorWithInlineCapacity<T, 0> baseCapacity;
+struct SameSizeAsVectorWithInlineCapacity : SameSizeAsVectorWithInlineCapacityBase<T> {
+ WTF_MAKE_NONCOPYABLE(SameSizeAsVectorWithInlineCapacity);
+public:
typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type inlineBuffer[inlineCapacity];
};
Modified: branches/safari-604.5.100-branch/Source/WTF/wtf/Vector.h (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/WTF/wtf/Vector.h 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/WTF/wtf/Vector.h 2017-12-19 23:00:51 UTC (rev 226144)
@@ -29,6 +29,7 @@
#include <wtf/CheckedArithmetic.h>
#include <wtf/FastMalloc.h>
#include <wtf/MallocPtr.h>
+#include <wtf/MathExtras.h>
#include <wtf/Noncopyable.h>
#include <wtf/NotFound.h>
#include <wtf/StdLibExtras.h>
@@ -265,6 +266,7 @@
CRASH();
size_t sizeToAllocate = newCapacity * sizeof(T);
m_capacity = sizeToAllocate / sizeof(T);
+ updateMask();
m_buffer = static_cast<T*>(fastMalloc(sizeToAllocate));
}
@@ -278,6 +280,7 @@
T* newBuffer;
if (tryFastMalloc(sizeToAllocate).getValue(newBuffer)) {
m_capacity = sizeToAllocate / sizeof(T);
+ updateMask();
m_buffer = newBuffer;
return true;
}
@@ -296,6 +299,7 @@
CRASH();
size_t sizeToAllocate = newCapacity * sizeof(T);
m_capacity = sizeToAllocate / sizeof(T);
+ updateMask();
m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate));
}
@@ -307,6 +311,7 @@
if (m_buffer == bufferToDeallocate) {
m_buffer = 0;
m_capacity = 0;
+ m_mask = 0;
}
fastFree(bufferToDeallocate);
@@ -322,6 +327,7 @@
T* buffer = m_buffer;
m_buffer = 0;
m_capacity = 0;
+ m_mask = 0;
return adoptMallocPtr(buffer);
}
@@ -330,6 +336,7 @@
: m_buffer(0)
, m_capacity(0)
, m_size(0)
+ , m_mask(0)
{
}
@@ -337,7 +344,9 @@
: m_buffer(buffer)
, m_capacity(capacity)
, m_size(size)
+ , m_mask(0)
{
+ updateMask();
}
~VectorBufferBase()
@@ -345,9 +354,15 @@
// FIXME: It would be nice to find a way to ASSERT that m_buffer hasn't leaked here.
}
+ void updateMask()
+ {
+ m_mask = maskForSize(m_capacity);
+ }
+
T* m_buffer;
unsigned m_capacity;
unsigned m_size; // Only used by the Vector subclass, but placed here to avoid padding the struct.
+ unsigned m_mask;
};
template<typename T, size_t inlineCapacity>
@@ -380,6 +395,7 @@
{
std::swap(m_buffer, other.m_buffer);
std::swap(m_capacity, other.m_capacity);
+ std::swap(m_mask, other.m_mask);
}
void restoreInlineBufferIfNeeded() { }
@@ -404,6 +420,7 @@
using Base::releaseBuffer;
protected:
+ using Base::m_mask;
using Base::m_size;
private:
@@ -442,6 +459,7 @@
else {
m_buffer = inlineBuffer();
m_capacity = inlineCapacity;
+ updateMask();
}
}
@@ -451,6 +469,7 @@
return Base::tryAllocateBuffer(newCapacity);
m_buffer = inlineBuffer();
m_capacity = inlineCapacity;
+ updateMask();
return true;
}
@@ -478,19 +497,23 @@
if (buffer() == inlineBuffer() && other.buffer() == other.inlineBuffer()) {
swapInlineBuffer(other, mySize, otherSize);
std::swap(m_capacity, other.m_capacity);
+ std::swap(m_mask, other.m_mask);
} else if (buffer() == inlineBuffer()) {
m_buffer = other.m_buffer;
other.m_buffer = other.inlineBuffer();
swapInlineBuffer(other, mySize, 0);
std::swap(m_capacity, other.m_capacity);
+ std::swap(m_mask, other.m_mask);
} else if (other.buffer() == other.inlineBuffer()) {
other.m_buffer = m_buffer;
m_buffer = inlineBuffer();
swapInlineBuffer(other, 0, otherSize);
std::swap(m_capacity, other.m_capacity);
+ std::swap(m_mask, other.m_mask);
} else {
std::swap(m_buffer, other.m_buffer);
std::swap(m_capacity, other.m_capacity);
+ std::swap(m_mask, other.m_mask);
}
}
@@ -500,6 +523,7 @@
return;
m_buffer = inlineBuffer();
m_capacity = inlineCapacity;
+ updateMask();
}
#if ASAN_ENABLED
@@ -527,11 +551,13 @@
}
protected:
+ using Base::m_mask;
using Base::m_size;
private:
using Base::m_buffer;
using Base::m_capacity;
+ using Base::updateMask;
void swapInlineBuffer(VectorBuffer& other, size_t mySize, size_t otherSize)
{
@@ -652,23 +678,23 @@
{
if (UNLIKELY(i >= size()))
OverflowHandler::overflowed();
- return Base::buffer()[i];
+ return Base::buffer()[i & m_mask];
}
const T& at(size_t i) const
{
if (UNLIKELY(i >= size()))
OverflowHandler::overflowed();
- return Base::buffer()[i];
+ return Base::buffer()[i & m_mask];
}
T& at(Checked<size_t> i)
{
RELEASE_ASSERT(i < size());
- return Base::buffer()[i];
+ return Base::buffer()[i & m_mask];
}
const T& at(Checked<size_t> i) const
{
RELEASE_ASSERT(i < size());
- return Base::buffer()[i];
+ return Base::buffer()[i & m_mask];
}
T& operator[](size_t i) { return at(i); }
@@ -798,6 +824,7 @@
void asanBufferSizeWillChangeTo(size_t);
+ using Base::m_mask;
using Base::m_size;
using Base::buffer;
using Base::capacity;
Modified: branches/safari-604.5.100-branch/Source/WTF/wtf/text/StringImpl.cpp (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/WTF/wtf/text/StringImpl.cpp 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/WTF/wtf/text/StringImpl.cpp 2017-12-19 23:00:51 UTC (rev 226144)
@@ -46,7 +46,7 @@
using namespace Unicode;
-static_assert(sizeof(StringImpl) == 2 * sizeof(int) + 2 * sizeof(void*), "StringImpl should stay small");
+static_assert(sizeof(StringImpl) == 2 * sizeof(int) + sizeof(void*) + 2 * sizeof(int), "StringImpl should stay small");
#if STRING_STATS
StringStats StringImpl::m_stringStats;
Modified: branches/safari-604.5.100-branch/Source/WTF/wtf/text/StringImpl.h (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/WTF/wtf/text/StringImpl.h 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/WTF/wtf/text/StringImpl.h 2017-12-19 23:00:51 UTC (rev 226144)
@@ -137,6 +137,7 @@
, m_length(length)
, m_data8(data8)
, m_hashAndFlags(hashAndFlags)
+ , m_mask(maskForSize(length))
{ }
StringImplShape(unsigned refCount, unsigned length, const UChar* data16, unsigned hashAndFlags)
@@ -144,6 +145,7 @@
, m_length(length)
, m_data16(data16)
, m_hashAndFlags(hashAndFlags)
+ , m_mask(maskForSize(length))
{ }
enum ConstructWithConstExprTag { ConstructWithConstExpr };
@@ -154,6 +156,7 @@
, m_length(length)
, m_data8Char(characters)
, m_hashAndFlags(hashAndFlags)
+ , m_mask(maskForSize(length))
{ }
template<unsigned charactersCount>
@@ -162,6 +165,7 @@
, m_length(length)
, m_data16Char(characters)
, m_hashAndFlags(hashAndFlags)
+ , m_mask(maskForSize(length))
{ }
unsigned m_refCount;
@@ -175,6 +179,7 @@
const char16_t* m_data16Char;
};
mutable unsigned m_hashAndFlags;
+ unsigned m_mask;
};
class StringImpl : private StringImplShape {
@@ -390,6 +395,7 @@
static unsigned flagIs8Bit() { return s_hashFlag8BitBuffer; }
static unsigned flagIsAtomic() { return s_hashFlagStringKindIsAtomic; }
static unsigned flagIsSymbol() { return s_hashFlagStringKindIsSymbol; }
+ static unsigned maskOffset() { return OBJECT_OFFSETOF(StringImpl, m_mask); }
static unsigned maskStringKind() { return s_hashMaskStringKind; }
static unsigned dataOffset() { return OBJECT_OFFSETOF(StringImpl, m_data8); }
@@ -409,6 +415,7 @@
WTF_EXPORT_STRING_API static Ref<StringImpl> adopt(StringBuffer<LChar>&&);
unsigned length() const { return m_length; }
+ unsigned mask() const { return m_mask; }
static ptrdiff_t lengthMemoryOffset() { return OBJECT_OFFSETOF(StringImpl, m_length); }
bool is8Bit() const { return m_hashAndFlags & s_hashFlag8BitBuffer; }
@@ -647,8 +654,8 @@
{
ASSERT_WITH_SECURITY_IMPLICATION(i < m_length);
if (is8Bit())
- return m_data8[i];
- return m_data16[i];
+ return m_data8[i & m_mask];
+ return m_data16[i & m_mask];
}
UChar operator[](unsigned i) const { return at(i); }
WTF_EXPORT_STRING_API UChar32 characterStartingAt(unsigned);
@@ -800,7 +807,7 @@
// MSVC doesn't support alignof yet.
return roundUpToMultipleOf<sizeof(T)>(sizeof(StringImpl));
#else
- return roundUpToMultipleOf<alignof(T)>(offsetof(StringImpl, m_hashAndFlags) + sizeof(StringImpl::m_hashAndFlags));
+ return roundUpToMultipleOf<alignof(T)>(offsetof(StringImpl, m_mask) + sizeof(StringImpl::m_mask));
#endif
}
Modified: branches/safari-604.5.100-branch/Source/WTF/wtf/text/StringView.h (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/WTF/wtf/text/StringView.h 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/WTF/wtf/text/StringView.h 2017-12-19 23:00:51 UTC (rev 226144)
@@ -156,6 +156,8 @@
void initialize(const LChar*, unsigned length);
void initialize(const UChar*, unsigned length);
+ void initialize(const LChar*, unsigned length, unsigned mask);
+ void initialize(const UChar*, unsigned length, unsigned mask);
#if CHECK_STRINGVIEW_LIFETIME
WTF_EXPORT_STRING_API bool underlyingStringIsValid() const;
@@ -170,6 +172,7 @@
const void* m_characters { nullptr };
unsigned m_length { 0 };
+ unsigned m_mask { 0 };
bool m_is8Bit { true };
#if CHECK_STRINGVIEW_LIFETIME
@@ -222,6 +225,7 @@
inline StringView::StringView(StringView&& other)
: m_characters(other.m_characters)
, m_length(other.m_length)
+ , m_mask(other.m_mask)
, m_is8Bit(other.m_is8Bit)
{
ASSERT(other.underlyingStringIsValid());
@@ -235,6 +239,7 @@
inline StringView::StringView(const StringView& other)
: m_characters(other.m_characters)
, m_length(other.m_length)
+ , m_mask(other.m_mask)
, m_is8Bit(other.m_is8Bit)
{
ASSERT(other.underlyingStringIsValid());
@@ -248,6 +253,7 @@
m_characters = other.m_characters;
m_length = other.m_length;
+ m_mask = other.m_mask;
m_is8Bit = other.m_is8Bit;
other.clear();
@@ -264,6 +270,7 @@
m_characters = other.m_characters;
m_length = other.m_length;
+ m_mask = other.m_mask;
m_is8Bit = other.m_is8Bit;
setUnderlyingString(other);
@@ -274,15 +281,27 @@
inline void StringView::initialize(const LChar* characters, unsigned length)
{
+ initialize(characters, length, maskForSize(length));
+}
+
+inline void StringView::initialize(const UChar* characters, unsigned length)
+{
+ initialize(characters, length, maskForSize(length));
+}
+
+inline void StringView::initialize(const LChar* characters, unsigned length, unsigned mask)
+{
m_characters = characters;
m_length = length;
+ m_mask = mask;
m_is8Bit = true;
}
-inline void StringView::initialize(const UChar* characters, unsigned length)
+inline void StringView::initialize(const UChar* characters, unsigned length, unsigned mask)
{
m_characters = characters;
m_length = length;
+ m_mask = mask;
m_is8Bit = false;
}
@@ -305,9 +324,9 @@
{
setUnderlyingString(&string);
if (string.is8Bit())
- initialize(string.characters8(), string.length());
+ initialize(string.characters8(), string.length(), string.mask());
else
- initialize(string.characters16(), string.length());
+ initialize(string.characters16(), string.length(), string.mask());
}
inline StringView::StringView(const StringImpl* string)
@@ -317,9 +336,9 @@
setUnderlyingString(string);
if (string->is8Bit())
- initialize(string->characters8(), string->length());
+ initialize(string->characters8(), string->length(), string->mask());
else
- initialize(string->characters16(), string->length());
+ initialize(string->characters16(), string->length(), string->mask());
}
inline StringView::StringView(const String& string)
@@ -330,10 +349,10 @@
return;
}
if (string.is8Bit()) {
- initialize(string.characters8(), string.length());
+ initialize(string.characters8(), string.length(), string.mask());
return;
}
- initialize(string.characters16(), string.length());
+ initialize(string.characters16(), string.length(), string.mask());
}
inline StringView::StringView(const AtomicString& atomicString)
@@ -345,6 +364,7 @@
{
m_characters = nullptr;
m_length = 0;
+ m_mask = 0;
m_is8Bit = true;
}
@@ -433,8 +453,8 @@
{
ASSERT(index < length());
if (is8Bit())
- return characters8()[index];
- return characters16()[index];
+ return characters8()[index & m_mask];
+ return characters16()[index & m_mask];
}
inline bool StringView::contains(UChar character) const
Modified: branches/safari-604.5.100-branch/Source/WTF/wtf/text/WTFString.h (226143 => 226144)
--- branches/safari-604.5.100-branch/Source/WTF/wtf/text/WTFString.h 2017-12-19 23:00:41 UTC (rev 226143)
+++ branches/safari-604.5.100-branch/Source/WTF/wtf/text/WTFString.h 2017-12-19 23:00:51 UTC (rev 226144)
@@ -176,6 +176,7 @@
ASSERT(!m_impl->is8Bit());
return m_impl->characters16();
}
+ unsigned mask() const { return m_impl ? m_impl->mask() : 0; }
// Return characters8() or characters16() depending on CharacterType.
template <typename CharacterType>