From 2a511ebb502c037e75e109ab0d98aa2546890a9e Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 10 Apr 2020 14:54:02 +1000 Subject: Backport: Move static functions into unnamed namespace and simplify line counting. Backport of changeset 8141:00d61c7df678. --- src/PerLine.cxx | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/PerLine.cxx b/src/PerLine.cxx index 933ed9839..085dccbaa 100644 --- a/src/PerLine.cxx +++ b/src/PerLine.cxx @@ -304,30 +304,37 @@ Sci::Line LineState::GetMaxLineState() const noexcept { return lineStates.Length(); } -static int NumberLines(const char *text) noexcept { +// Each allocated LineAnnotation is a char array which starts with an AnnotationHeader +// and then has text and optional styles. + +struct AnnotationHeader { + short style; // Style IndividualStyles implies array of styles + short lines; + int length; +}; + +namespace { + +constexpr int IndividualStyles = 0x100; + +size_t NumberLines(const char *text) noexcept { + int lines = 1; if (text) { - int newLines = 0; while (*text) { if (*text == '\n') - newLines++; + lines++; text++; } - return newLines+1; - } else { - return 0; } + return lines; } -// Each allocated LineAnnotation is a char array which starts with an AnnotationHeader -// and then has text and optional styles. - -static constexpr int IndividualStyles = 0x100; +std::unique_ptrAllocateAnnotation(size_t length, int style) { + const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0); + return Sci::make_unique(len); +} -struct AnnotationHeader { - short style; // Style IndividualStyles implies array of styles - short lines; - int length; -}; +} LineAnnotation::~LineAnnotation() { } @@ -378,11 +385,6 @@ const unsigned char *LineAnnotation::Styles(Sci::Line line) const noexcept { return nullptr; } -static std::unique_ptrAllocateAnnotation(size_t length, int style) { - const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0); - return Sci::make_unique(len); -} - void LineAnnotation::SetText(Sci::Line line, const char *text) { if (text && (line >= 0)) { annotations.EnsureLength(line+1); -- cgit v1.2.3