Commit 24873c03 authored by pdr's avatar pdr Committed by Commit bot

Change TextRun's length() and charactersLength() to return an unsigned

TextRun's m_len and m_charactersLength are unsigned but the accessors
for these values return ints. The values for length and charactersLength
cannot be negative so returning an integer just adds unnecessary casts
and potentially dangerous code.

Review-Url: https://codereview.chromium.org/2018253002
Cr-Commit-Position: refs/heads/master@{#396776}
parent 26acd288
......@@ -197,7 +197,7 @@ inline bool isValidSurrogatePair(const TextRun& run, unsigned index)
{
if (!U16_IS_LEAD(run[index]))
return false;
if (index + 1 >= static_cast<unsigned>(run.length()))
if (index + 1 >= run.length())
return false;
return U16_IS_TRAIL(run[index + 1]);
}
......@@ -275,7 +275,7 @@ void LayoutSVGInlineText::addMetricsFromRun(
const float cachedFontHeight = scaledFont().getFontMetrics().floatHeight() / m_scalingFactor;
const bool preserveWhiteSpace = styleRef().whiteSpace() == PRE;
const unsigned runLength = static_cast<unsigned>(run.length());
const unsigned runLength = run.length();
// TODO(pdr): Character-based iteration is ambiguous and error-prone. It
// should be unified under a single concept. See: https://crbug.com/593570
......
......@@ -54,7 +54,7 @@ void TextPainter::setEmphasisMark(const AtomicString& emphasisMark, TextEmphasis
}
}
void TextPainter::paint(int startOffset, int endOffset, int length, const Style& textStyle, TextBlobPtr* cachedTextBlob)
void TextPainter::paint(unsigned startOffset, unsigned endOffset, unsigned length, const Style& textStyle, TextBlobPtr* cachedTextBlob)
{
GraphicsContextStateSaver stateSaver(m_graphicsContext, false);
updateGraphicsContext(textStyle, stateSaver);
......@@ -183,7 +183,7 @@ TextPainter::Style TextPainter::selectionPaintingStyle(LineLayoutItem lineLayout
}
template <TextPainter::PaintInternalStep step>
void TextPainter::paintInternalRun(TextRunPaintInfo& textRunPaintInfo, int from, int to)
void TextPainter::paintInternalRun(TextRunPaintInfo& textRunPaintInfo, unsigned from, unsigned to)
{
ASSERT(from <= textRunPaintInfo.run.length());
ASSERT(to <= textRunPaintInfo.run.length());
......@@ -201,7 +201,7 @@ void TextPainter::paintInternalRun(TextRunPaintInfo& textRunPaintInfo, int from,
}
template <TextPainter::PaintInternalStep Step>
void TextPainter::paintInternal(int startOffset, int endOffset, int truncationPoint, TextBlobPtr* cachedTextBlob)
void TextPainter::paintInternal(unsigned startOffset, unsigned endOffset, unsigned truncationPoint, TextBlobPtr* cachedTextBlob)
{
TextRunPaintInfo textRunPaintInfo(m_run);
textRunPaintInfo.bounds = FloatRect(m_textBounds);
......
......@@ -43,7 +43,7 @@ public:
static void updateGraphicsContext(GraphicsContext&, const Style&, bool horizontal, GraphicsContextStateSaver&);
void paint(int startOffset, int endOffset, int length, const Style&, TextBlobPtr* cachedTextBlob = 0);
void paint(unsigned startOffset, unsigned endOffset, unsigned length, const Style&, TextBlobPtr* cachedTextBlob = 0);
struct Style {
STACK_ALLOCATED();
......@@ -80,10 +80,10 @@ private:
enum PaintInternalStep { PaintText, PaintEmphasisMark };
template <PaintInternalStep step>
void paintInternalRun(TextRunPaintInfo&, int from, int to);
void paintInternalRun(TextRunPaintInfo&, unsigned from, unsigned to);
template <PaintInternalStep step>
void paintInternal(int startOffset, int endOffset, int truncationPoint, TextBlobPtr* cachedTextBlob = 0);
void paintInternal(unsigned startOffset, unsigned endOffset, unsigned truncationPoint, TextBlobPtr* cachedTextBlob = 0);
void paintEmphasisMarkForCombinedText();
......
......@@ -768,7 +768,7 @@ Vector<CharacterRange> Font::individualCharacterRanges(const TextRun& run) const
FontCachePurgePreventer purgePreventer;
CachingWordShaper shaper(m_fontFallbackList->shapeCache(m_fontDescription));
auto ranges = shaper.individualCharacterRanges(this, run);
DCHECK_EQ(ranges.size(), static_cast<unsigned>(run.length()));
DCHECK_EQ(ranges.size(), run.length());
return ranges;
}
......
......@@ -137,7 +137,7 @@ public:
ShapeCacheEntry* add(const TextRun& run, ShapeCacheEntry entry)
{
if (static_cast<unsigned>(run.length()) > SmallStringKey::capacity())
if (run.length() > SmallStringKey::capacity())
return 0;
return addSlowCase(run, entry);
......@@ -182,7 +182,7 @@ public:
private:
ShapeCacheEntry* addSlowCase(const TextRun& run, ShapeCacheEntry entry)
{
int length = run.length();
unsigned length = run.length();
bool isNewEntry;
ShapeCacheEntry *value;
if (length == 1) {
......
......@@ -205,7 +205,7 @@ float ShapeResultBuffer::fillGlyphBuffer(GlyphBuffer* glyphBuffer, const TextRun
unsigned from, unsigned to) const
{
// Fast path: full run with no vertical offsets
if (!from && to == static_cast<unsigned>(textRun.length()) && !hasVerticalOffsets())
if (!from && to == textRun.length() && !hasVerticalOffsets())
return fillFastHorizontalGlyphBuffer(glyphBuffer, textRun.direction());
float advance = 0;
......
......@@ -99,7 +99,7 @@ float SimpleShaper::adjustSpacing(float width, const CharacterData& charData)
m_runWidthSoFar += m_expansionPerOpportunity;
}
if (m_textRun.allowsTrailingExpansion()
|| (m_textRun.ltr() && charData.characterOffset + charData.clusterLength < static_cast<size_t>(m_textRun.length()))
|| (m_textRun.ltr() && charData.characterOffset + charData.clusterLength < m_textRun.length())
|| (m_textRun.rtl() && charData.characterOffset)) {
m_expansion -= m_expansionPerOpportunity;
width += m_expansionPerOpportunity;
......
......@@ -177,8 +177,8 @@ public:
const UChar* characters16() const { ASSERT(!is8Bit()); return m_data.characters16; }
bool is8Bit() const { return m_is8Bit; }
int length() const { return m_len; }
int charactersLength() const { return m_charactersLength; }
unsigned length() const { return m_len; }
unsigned charactersLength() const { return m_charactersLength; }
bool normalizeSpace() const { return m_normalizeSpace; }
void setNormalizeSpace(bool normalizeSpace) { m_normalizeSpace = normalizeSpace; }
......@@ -259,8 +259,8 @@ public:
}
const TextRun& run;
int from;
int to;
unsigned from;
unsigned to;
FloatRect bounds;
RefPtr<const SkTextBlob>* cachedTextBlob;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment