move Run::calculateWidth to improve inlining

This exposes the implementation of calculateWidth to the
cluster building function. It improves performance by 2-3%.

Change-Id: I6be71ef2c9bdd4fb59531fc53cc3868434cba79d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/387216
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Julia Lavrova <jlavrova@google.com>
This commit is contained in:
Herb Derby 2021-03-19 14:00:01 -04:00 committed by Skia Commit-Bot
parent 339f7ea5a0
commit 980fb4de3a
2 changed files with 16 additions and 15 deletions

View File

@ -365,6 +365,22 @@ Cluster::Cluster(ParagraphImpl* owner,
fIsHardBreak = fOwner->codeUnitHasProperty(fTextRange.end, CodeUnitFlags::kHardLineBreakBefore);
}
SkScalar Run::calculateWidth(size_t start, size_t end, bool clip) const {
SkASSERT(start <= end);
// clip |= end == size(); // Clip at the end of the run?
SkScalar shift = 0;
if (fSpaced && end > start) {
shift = fShifts[clip ? end - 1 : end] - fShifts[start];
}
auto correction = 0.0f;
if (end > start && !fJustificationShifts.empty()) {
// This is not a typo: we are using Point as a pair of SkScalars
correction = fJustificationShifts[end - 1].fX -
fJustificationShifts[start].fY;
}
return posX(end) - posX(start) + shift + correction;
}
// Clusters in the order of the input text
void ParagraphImpl::buildClusterTable() {
int cluster_count = 1;

View File

@ -68,21 +68,6 @@ SkShaper::RunHandler::Buffer Run::newRunBuffer() {
void Run::commit() {
fFont.getBounds(fGlyphs.data(), fGlyphs.size(), fBounds.data(), nullptr);
}
SkScalar Run::calculateWidth(size_t start, size_t end, bool clip) const {
SkASSERT(start <= end);
// clip |= end == size(); // Clip at the end of the run?
SkScalar shift = 0;
if (fSpaced && end > start) {
shift = fShifts[clip ? end - 1 : end] - fShifts[start];
}
auto correction = 0.0f;
if (end > start && !fJustificationShifts.empty()) {
// This is not a typo: we are using Point as a pair of SkScalars
correction = fJustificationShifts[end - 1].fX -
fJustificationShifts[start].fY;
}
return posX(end) - posX(start) + shift + correction;
}
void Run::copyTo(SkTextBlobBuilder& builder, size_t pos, size_t size) const {
SkASSERT(pos + size <= this->size());