From 60e87889d6438e386acf58c3967fb874af9aae82 Mon Sep 17 00:00:00 2001 From: mitchell Date: Sun, 5 Jan 2020 21:22:02 -0500 Subject: Added Sci::make_unique() and Sci::size() for better compatibility with the default branch. std::make_unique() is c++14 and std::size() is c++17. --- src/PerLine.cxx | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/PerLine.cxx') diff --git a/src/PerLine.cxx b/src/PerLine.cxx index d81f46d3b..e67426ae7 100644 --- a/src/PerLine.cxx +++ b/src/PerLine.cxx @@ -118,7 +118,7 @@ Sci::Line LineMarkers::LineFromHandle(int markerHandle) { void LineMarkers::MergeMarkers(Sci::Line line) { if (markers[line + 1]) { if (!markers[line]) - markers[line].reset(new MarkerHandleSet); + markers[line] = Sci::make_unique(); markers[line]->CombineWith(markers[line + 1].get()); markers[line + 1].reset(); } @@ -154,7 +154,7 @@ int LineMarkers::AddMark(Sci::Line line, int markerNum, Sci::Line lines) { } if (!markers[line]) { // Need new structure to hold marker handle - markers[line].reset(new MarkerHandleSet()); + markers[line] = Sci::make_unique(); } markers[line]->InsertHandle(handleCurrent, markerNum); @@ -357,17 +357,16 @@ const unsigned char *LineAnnotation::Styles(Sci::Line line) const { return nullptr; } -static char *AllocateAnnotation(int length, int style) { +static std::unique_ptrAllocateAnnotation(int length, int style) { const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0); - char *ret = new char[len](); - return ret; + return Sci::make_unique(len); } void LineAnnotation::SetText(Sci::Line line, const char *text) { if (text && (line >= 0)) { annotations.EnsureLength(line+1); const int style = Style(line); - annotations[line].reset(AllocateAnnotation(static_cast(strlen(text)), style)); + annotations[line] = AllocateAnnotation(static_cast(strlen(text)), style); char *pa = annotations[line].get(); assert(pa); AnnotationHeader *pah = reinterpret_cast(pa); @@ -389,7 +388,7 @@ void LineAnnotation::ClearAll() { void LineAnnotation::SetStyle(Sci::Line line, int style) { annotations.EnsureLength(line+1); if (!annotations[line]) { - annotations[line].reset(AllocateAnnotation(0, style)); + annotations[line] = AllocateAnnotation(0, style); } reinterpret_cast(annotations[line].get())->style = static_cast(style); } @@ -398,16 +397,16 @@ void LineAnnotation::SetStyles(Sci::Line line, const unsigned char *styles) { if (line >= 0) { annotations.EnsureLength(line+1); if (!annotations[line]) { - annotations[line].reset(AllocateAnnotation(0, IndividualStyles)); + annotations[line] = AllocateAnnotation(0, IndividualStyles); } else { const AnnotationHeader *pahSource = reinterpret_cast(annotations[line].get()); if (pahSource->style != IndividualStyles) { - char *allocation = AllocateAnnotation(pahSource->length, IndividualStyles); - AnnotationHeader *pahAlloc = reinterpret_cast(allocation); + std::unique_ptrallocation = AllocateAnnotation(pahSource->length, IndividualStyles); + AnnotationHeader *pahAlloc = reinterpret_cast(allocation.get()); pahAlloc->length = pahSource->length; pahAlloc->lines = pahSource->lines; - memcpy(allocation + sizeof(AnnotationHeader), annotations[line].get() + sizeof(AnnotationHeader), pahSource->length); - annotations[line].reset(allocation); + memcpy(allocation.get() + sizeof(AnnotationHeader), annotations[line].get() + sizeof(AnnotationHeader), pahSource->length); + annotations[line] = std::move(allocation); } } AnnotationHeader *pah = reinterpret_cast(annotations[line].get()); @@ -465,7 +464,7 @@ bool LineTabstops::ClearTabstops(Sci::Line line) { bool LineTabstops::AddTabstop(Sci::Line line, int x) { tabstops.EnsureLength(line + 1); if (!tabstops[line]) { - tabstops[line].reset(new TabstopList()); + tabstops[line] = Sci::make_unique(); } TabstopList *tl = tabstops[line].get(); -- cgit v1.2.3