aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2020-04-10 14:54:02 +1000
committerNeil <nyamatongwe@gmail.com>2020-04-10 14:54:02 +1000
commit2a511ebb502c037e75e109ab0d98aa2546890a9e (patch)
treeb0731bd924e7ed27428757489505cfe5d157e1b5
parentb64e26f709cfe09b3990b7c7e6760af2b98ef83a (diff)
downloadscintilla-mirror-2a511ebb502c037e75e109ab0d98aa2546890a9e.tar.gz
Backport: Move static functions into unnamed namespace and simplify line counting.
Backport of changeset 8141:00d61c7df678.
-rw-r--r--src/PerLine.cxx42
1 files changed, 22 insertions, 20 deletions
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_ptr<char[]>AllocateAnnotation(size_t length, int style) {
+ const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0);
+ return Sci::make_unique<char[]>(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_ptr<char[]>AllocateAnnotation(size_t length, int style) {
- const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0);
- return Sci::make_unique<char[]>(len);
-}
-
void LineAnnotation::SetText(Sci::Line line, const char *text) {
if (text && (line >= 0)) {
annotations.EnsureLength(line+1);