From e21a8ca7ecf4001bb3c9a6bcc9d415e60ba2b303 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 15 Oct 2018 09:05:52 +1100 Subject: Extract duration measurement damping and clamping into ActionDuration class so that it can be reused. --- src/Document.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/Document.h') diff --git a/src/Document.h b/src/Document.h index 0ef967e09..19a03ad1d 100644 --- a/src/Document.h +++ b/src/Document.h @@ -189,6 +189,26 @@ struct RegexError : public std::runtime_error { RegexError() : std::runtime_error("regex failure") {} }; +/** + * The ActionDuration class stores the average time taken for some action such as styling or + * wrapping a line. It is used to decide how many repetitions of that action can be performed + * on idle to maximize efficiency without affecting application responsiveness. + * The duration changes if the time for the action changes. For example, if a simple lexer is + * changed to a complex lexer. Changes are damped and clamped to avoid short periods of easy + * or difficult processing moving the value too far leading to inefficiency or poor user + * experience. + */ + +class ActionDuration { + double duration; + const double minDuration; + const double maxDuration; +public: + ActionDuration(double duration_, double minDuration_, double maxDuration_) noexcept; + void AddSample(size_t numberActions, double durationOfActions) noexcept; + double Duration() const noexcept; +}; + /** */ class Document : PerLine, public IDocument, public ILoader { @@ -259,7 +279,7 @@ public: bool useTabs; bool tabIndents; bool backspaceUnindents; - double durationStyleOneLine; + ActionDuration durationStyleOneLine; std::unique_ptr decorations; -- cgit v1.2.3