diff options
author | Raphael Isemann <teemperor@gmail.com> | 2018-08-14 17:12:54 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2018-08-14 17:12:54 +0000 |
commit | 2d437f6b026c4f8ccb6e1daac412dd788e76b25a (patch) | |
tree | 5f4767bffbfaa0c8f26615160b88807f8a214327 /lldb/source/Core/SourceManager.cpp | |
parent | 148c44547567bc2410e8adf3d31e7eefa62f7051 (diff) | |
download | bcm5719-llvm-2d437f6b026c4f8ccb6e1daac412dd788e76b25a.tar.gz bcm5719-llvm-2d437f6b026c4f8ccb6e1daac412dd788e76b25a.zip |
Remove manual byte counting from Highlighter code.
Summary:
This removes the manual byte counting mechanism from the syntax highlighting
code. This is no longer necessary as the Stream class now has built-in support for
automatically counting the bytes that were written to it so far.
The advantage of automatic byte counting via Stream is that it is less error-prone
than the manual version and we need to write less boilerplate code.
Reviewers: labath
Reviewed By: labath
Subscribers: labath, lldb-commits
Differential Revision: https://reviews.llvm.org/D50676
llvm-svn: 339695
Diffstat (limited to 'lldb/source/Core/SourceManager.cpp')
-rw-r--r-- | lldb/source/Core/SourceManager.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp index 0ae1d9b9f0d..c14b72250e7 100644 --- a/lldb/source/Core/SourceManager.cpp +++ b/lldb/source/Core/SourceManager.cpp @@ -533,6 +533,8 @@ size_t SourceManager::File::DisplaySourceLines(uint32_t line, uint32_t column, if (!m_data_sp) return 0; + size_t bytes_written = s->GetWrittenBytes(); + std::string previous_content; HighlightStyle style = HighlightStyle::MakeVimStyle(); @@ -553,7 +555,6 @@ size_t SourceManager::File::DisplaySourceLines(uint32_t line, uint32_t column, end_line_offset = m_data_sp->GetByteSize(); assert(start_line_offset <= end_line_offset); - size_t bytes_written = 0; if (start_line_offset < end_line_offset) { size_t count = end_line_offset - start_line_offset; const uint8_t *cstr = m_data_sp->GetBytes() + start_line_offset; @@ -563,8 +564,7 @@ size_t SourceManager::File::DisplaySourceLines(uint32_t line, uint32_t column, auto debugger_sp = m_debugger_wp.lock(); if (should_highlight_source(debugger_sp)) { - bytes_written += - highlighter.Highlight(style, ref, previous_content, *s); + highlighter.Highlight(style, ref, previous_content, *s); displayed_line = true; // Add the new line to the previous lines. previous_content += ref.str(); @@ -586,7 +586,7 @@ size_t SourceManager::File::DisplaySourceLines(uint32_t line, uint32_t column, // formatting the column (e.g. underline, inverse, etc.) // First print the part before the column to mark. - bytes_written = s->Write(cstr, column - 1); + s->Write(cstr, column - 1); // Write the pre escape sequence. const SymbolContext *sc = nullptr; @@ -599,15 +599,14 @@ size_t SourceManager::File::DisplaySourceLines(uint32_t line, uint32_t column, FormatEntity::Format(*ansi_prefix_entry, *s, sc, exe_ctx, &addr, valobj, function_changed, initial_function); - // Write the marked column. - bytes_written += s->Write(cstr + column - 1, 1); + s->Write(cstr + column - 1, 1); // Write the post escape sequence. FormatEntity::Format(*ansi_suffix_entry, *s, sc, exe_ctx, &addr, valobj, function_changed, initial_function); // And finish up with the rest of the line. - bytes_written += s->Write(cstr + column, count - column); + s->Write(cstr + column, count - column); // Keep track of the fact that we just wrote the line. displayed_line = true; @@ -618,15 +617,14 @@ size_t SourceManager::File::DisplaySourceLines(uint32_t line, uint32_t column, // If we didn't end up displaying the line with ANSI codes for whatever // reason, display it now sans codes. if (!displayed_line) - bytes_written = s->PutCString(ref); + s->PutCString(ref); // Ensure we get an end of line character one way or another. if (!is_newline_char(ref.back())) - bytes_written += s->EOL(); + s->EOL(); } - return bytes_written; } - return 0; + return s->GetWrittenBytes() - bytes_written; } void SourceManager::File::FindLinesMatchingRegex( |