Skip to content

Commit

Permalink
Remove old timing code for idle line wrapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Jan 14, 2022
1 parent 191ca54 commit 3750f79
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 65 deletions.
4 changes: 0 additions & 4 deletions scintilla/src/Document.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ void ActionDuration::AddSample(Sci::Position numberActions, double durationOfAct
// durationOfActions, numberActions, durationOne, duration_, duration, minDuration, maxDuration);
}

double ActionDuration::Duration() const noexcept {
return duration;
}

Sci::Position ActionDuration::ActionsInAllowedTime(double secondsAllowed) const noexcept {
const Sci::Position actions = std::clamp<Sci::Position>(static_cast<Sci::Position>(secondsAllowed / duration), 8, 0x10000);
return actions * unitBytes;
Expand Down
4 changes: 3 additions & 1 deletion scintilla/src/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ class ActionDuration {
public:
static constexpr int InitialBytes = 1024*1024;
void AddSample(Sci::Position numberActions, double durationOfActions) noexcept;
double Duration() const noexcept;
double Duration() const noexcept {
return duration;
}
Sci::Position ActionsInAllowedTime(double secondsAllowed) const noexcept;
};

Expand Down
16 changes: 8 additions & 8 deletions scintilla/src/EditView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,10 @@ constexpr WrapBreak GetWrapBreakEx(unsigned int ch, bool isUtf8) noexcept {
* Also determine the x position at which each character starts.
*/
int EditView::LayoutLine(const EditModel &model, Surface *surface, const ViewStyle &vstyle, LineLayout *ll, int width, LayoutLineOption option, int posInLine) {
int wrappedBytes = 0; // only care about time spend on MeasureWidths()
const Sci::Line line = ll->LineNumber();
PLATFORM_ASSERT(line < model.pdoc->LinesTotal());
PLATFORM_ASSERT(ll->chars);
int laidBytes = 0; // lower bound, only care time spend on MeasureWidths()
const Sci::Position posLineStart = model.pdoc->LineStart(line);
// If the line is very long, limit the treatment to a length that should fit in the viewport
const Sci::Position posLineEnd = std::min(model.pdoc->LineStart(line + 1), posLineStart + ll->maxLineLength);
Expand Down Expand Up @@ -588,11 +588,11 @@ int EditView::LayoutLine(const EditModel &model, Surface *surface, const ViewSty

if (endPos > posInLine && model.IdleTaskTimeExpired()) {
// treat remaining text as zero width
//printf("%s(%d, %zd) posInLine=%d, lineLength=%d / %d, laidBytes=%d - %d\n", __func__,
// (int)option, line, posInLine, laidBytes, ll->numCharsInLine, endPos, ll->lastSegmentEnd);
//printf("%s(%d, %zd) posInLine=%d, lineLength=%d / %d, wrappedBytes=%d - %d\n", __func__,
// (int)option, line, posInLine, wrappedBytes, ll->numCharsInLine, endPos, ll->lastSegmentEnd);
if (endPos < ll->numCharsInLine) {
wholeLine = false;
laidBytes = endPos - ll->lastSegmentEnd;
wrappedBytes = endPos - ll->lastSegmentEnd;
ll->lastSegmentEnd = endPos;
const XYPOSITION last = ll->positions[endPos];
std::fill(&ll->positions[endPos + 1], &ll->positions[ll->numCharsInLine + 1], last);
Expand All @@ -603,7 +603,7 @@ int EditView::LayoutLine(const EditModel &model, Surface *surface, const ViewSty

// Small hack to make lines that end with italics not cut off the edge of the last character
if (wholeLine) {
laidBytes = ll->numCharsInLine - ll->lastSegmentEnd;
wrappedBytes = ll->numCharsInLine - ll->lastSegmentEnd;
ll->lastSegmentEnd = ll->numCharsInLine;
if (lastSegItalics) {
ll->positions[ll->numCharsInLine] += vstyle.lastSegItalicsOffset;
Expand Down Expand Up @@ -772,7 +772,7 @@ int EditView::LayoutLine(const EditModel &model, Surface *surface, const ViewSty
}
}
ll->validity = validity;
return laidBytes;
return wrappedBytes;
}

// Fill the LineLayout bidirectional data fields according to each char style
Expand Down Expand Up @@ -2633,7 +2633,7 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan
LayoutLine(model, surface, vsDraw, ll, model.wrapWidth, LayoutLineOption::KeepPosition);
}
#if defined(TIME_PAINTING)
durLayout += ep.Duration(true);
durLayout += ep.Reset();
#endif
if (ll) {
ll->containsCaret = !hideSelection && (lineDoc == lineCaret)
Expand Down Expand Up @@ -2665,7 +2665,7 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan

DrawLine(surface, model, vsDraw, ll, lineDoc, visibleLine, xStart, rcLine, subLine, phase);
#if defined(TIME_PAINTING)
durPaint += ep.Duration(true);
durPaint += ep.Reset();
#endif
// Restore the previous styles for the brace highlights in case layout is in cache.
ll->RestoreBracesHighlight(rangeLine, model.braces, bracesIgnoreStyle);
Expand Down
4 changes: 2 additions & 2 deletions scintilla/src/EditView.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ enum class DrawPhase {
};

enum class LayoutLineOption {
AutoUpdate ,
ManualUpdate ,
AutoUpdate,
ManualUpdate,
KeepPosition,
};

Expand Down
46 changes: 0 additions & 46 deletions scintilla/src/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1530,34 +1530,6 @@ void Editor::OnLineWrapped(Sci::Line lineDoc, int linesWrapped) {
// wsIdle: wrap one page + 100 lines
// Return true if wrapping occurred.
bool Editor::WrapLines(WrapScope ws) {
//#define WRAP_LINES_TIMING
#ifdef WRAP_LINES_TIMING
struct WrapTiming {
size_t totalBytes;
size_t totalRuns;
double totalDuration;
using Clock = std::chrono::steady_clock;
Clock::time_point startTime;

void Reset() noexcept {
totalBytes = 0;
totalRuns = 0;
totalDuration = 0;
}
void Add(size_t bytes, double duration) noexcept {
totalBytes += bytes;
++totalRuns;
totalDuration += duration;
}
double TotalTime() const noexcept {
const auto tpNow = Clock::now();
const auto duration = std::chrono::duration_cast<std::chrono::duration<double>>(tpNow - startTime);
return duration.count();
}
};

static WrapTiming wrapTiming;
#endif
Sci::Line goodTopLine = topLine;
bool wrapOccurred = false;
if (!Wrapping()) {
Expand All @@ -1581,13 +1553,6 @@ bool Editor::WrapLines(WrapScope ws) {
}
// Decide where to start wrapping
Sci::Line lineToWrap = wrapPending.start;
#ifdef WRAP_LINES_TIMING
if (lineToWrap == 0) {
printf("%s wrap start ws=%d, modEventMask=%x\n", __func__, ws, modEventMask);
wrapTiming.Reset();
wrapTiming.startTime = WrapTiming::Clock::now();
}
#endif
Sci::Line lineToWrapEnd = std::min(wrapPending.end, pdoc->LinesTotal());
const Sci::Line lineDocTop = pcs->DocFromDisplay(topLine);
const Sci::Line subLineTop = topLine - pcs->DisplayFromDoc(lineDocTop);
Expand Down Expand Up @@ -1655,9 +1620,6 @@ bool Editor::WrapLines(WrapScope ws) {
lineToWrap++;
}
const double duration = epWrapping.Duration();
#ifdef WRAP_LINES_TIMING
wrapTiming.Add(bytesBeingWrapped, duration);
#endif
durationWrapOneUnit.AddSample(bytesBeingWrapped, duration);

goodTopLine = pcs->DisplayFromDoc(lineDocTop) + std::min(
Expand All @@ -1669,14 +1631,6 @@ bool Editor::WrapLines(WrapScope ws) {
if (!partialLine && wrapPending.start >= lineEndNeedWrap) {
//printf("%s durationStyleOneUnit: %f\n", __func__, durationWrapOneUnit.Duration()*1e3);
wrapPending.Reset();
#ifdef WRAP_LINES_TIMING
const double totalTime = wrapTiming.TotalTime();
printf("%s bytes=%zu / %zu, time=%.6f / %.6f, level=%d,\n"
"\tLinesOnScreen=%zd, idleStyling=%d, modEventMask=%x, technology=%d, dbcsCodePage=%d\n",
__func__, wrapTiming.totalBytes, wrapTiming.totalRuns, wrapTiming.totalDuration, totalTime,
view.llc.GetLevel(), LinesOnScreen(), idleStyling, modEventMask, technology, pdoc->dbcsCodePage);
wrapTiming.Reset();
#endif
}
}

Expand Down
6 changes: 2 additions & 4 deletions scintilla/src/ElapsedPeriod.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ class ElapsedPeriod {
/// Capture the moment
ElapsedPeriod() noexcept : tp(ElapsedClock::now()) {}
/// Return duration as floating point seconds
double Duration(bool reset) noexcept {
double Reset() noexcept {
const auto tpNow = ElapsedClock::now();
const auto duration = std::chrono::duration_cast<std::chrono::duration<double>>(tpNow - tp);
if (reset) {
tp = tpNow;
}
tp = tpNow;
return duration.count();
}

Expand Down

0 comments on commit 3750f79

Please sign in to comment.