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/CallTip.cxx | 5 ++--- src/CaseConvert.cxx | 6 ++++-- src/CellBuffer.cxx | 6 +++--- src/ContractionState.cxx | 14 +++++++------- src/Decoration.cxx | 10 +++++----- src/Document.cxx | 10 +++++----- src/EditView.cxx | 5 ++--- src/Editor.cxx | 7 +++---- src/ExternalLexer.cxx | 3 +-- src/Indicator.cxx | 3 +-- src/LineMarker.cxx | 29 ++++++++++++++--------------- src/Partitioning.h | 4 +++- src/PerLine.cxx | 25 ++++++++++++------------- src/PositionCache.cxx | 18 +++++++++--------- src/RunStyles.cxx | 8 ++++---- src/SparseVector.h | 4 ++-- src/UniqueString.cxx | 4 ++-- src/UniqueString.h | 2 ++ src/ViewStyle.cxx | 2 +- 19 files changed, 82 insertions(+), 83 deletions(-) (limited to 'src') diff --git a/src/CallTip.cxx b/src/CallTip.cxx index 18c4549bb..db66878ce 100644 --- a/src/CallTip.cxx +++ b/src/CallTip.cxx @@ -21,7 +21,6 @@ #include "Scintilla.h" -#include "StringCopy.h" #include "Position.h" #include "IntegerRectangle.h" #include "CallTip.h" @@ -135,14 +134,14 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s, Point::FromInts(centreX + halfWidth, centreY + quarterWidth), Point::FromInts(centreX, centreY - halfWidth + quarterWidth), }; - surface->Polygon(pts, ELEMENTS(pts), colourBG, colourBG); + surface->Polygon(pts, Sci::size(pts), colourBG, colourBG); } else { // Down arrow Point pts[] = { Point::FromInts(centreX - halfWidth, centreY - quarterWidth), Point::FromInts(centreX + halfWidth, centreY - quarterWidth), Point::FromInts(centreX, centreY + halfWidth - quarterWidth), }; - surface->Polygon(pts, ELEMENTS(pts), colourBG, colourBG); + surface->Polygon(pts, Sci::size(pts), colourBG, colourBG); } } offsetMain = xEnd; diff --git a/src/CaseConvert.cxx b/src/CaseConvert.cxx index ed94a67f1..dd8a25aa1 100644 --- a/src/CaseConvert.cxx +++ b/src/CaseConvert.cxx @@ -19,6 +19,8 @@ #include "CaseConvert.h" #include "UniConversion.h" +#include "Compat.h" + using namespace Scintilla; namespace { @@ -692,7 +694,7 @@ void AddSymmetric(enum CaseConversion conversion, int lower,int upper) { void SetupConversions(enum CaseConversion conversion) { // First initialize for the symmetric ranges - for (size_t i=0; i(new char[lenData_]); + data = Sci::make_unique(lenData_); memcpy(&data[0], data_, lenData_); } lenData = lenData_; @@ -534,9 +534,9 @@ CellBuffer::CellBuffer(bool hasStyles_, bool largeDocument_) : utf8LineEnds = 0; collectingUndo = true; if (largeDocument) - plv = std::unique_ptr>(new LineVector()); + plv = Sci::make_unique>(); else - plv = std::unique_ptr>(new LineVector()); + plv = Sci::make_unique>(); } CellBuffer::~CellBuffer() { diff --git a/src/ContractionState.cxx b/src/ContractionState.cxx index ebbf9aefe..8d2427629 100644 --- a/src/ContractionState.cxx +++ b/src/ContractionState.cxx @@ -100,11 +100,11 @@ ContractionState::~ContractionState() { template void ContractionState::EnsureData() { if (OneToOne()) { - visible = std::unique_ptr>(new RunStyles()); - expanded = std::unique_ptr>(new RunStyles()); - heights = std::unique_ptr>(new RunStyles()); - foldDisplayTexts = std::unique_ptr>(new SparseVector()); - displayLines = std::unique_ptr>(new Partitioning(4)); + visible = Sci::make_unique>(); + expanded = Sci::make_unique>(); + heights = Sci::make_unique>(); + foldDisplayTexts = Sci::make_unique>(); + displayLines = Sci::make_unique>(4); InsertLines(0, linesInDocument); } } @@ -412,9 +412,9 @@ namespace Scintilla { std::unique_ptr ContractionStateCreate(bool largeDocument) { if (largeDocument) - return std::unique_ptr>(new ContractionState()); + return Sci::make_unique>(); else - return std::unique_ptr>(new ContractionState()); + return Sci::make_unique>(); } } diff --git a/src/Decoration.cxx b/src/Decoration.cxx index 8d60d8935..813e988d0 100644 --- a/src/Decoration.cxx +++ b/src/Decoration.cxx @@ -143,7 +143,7 @@ Decoration *DecorationList::DecorationFromIndicator(int indicator) { template Decoration *DecorationList::Create(int indicator, Sci::Position length) { currentIndicator = indicator; - std::unique_ptr> decoNew = std::unique_ptr>(new Decoration(indicator)); + std::unique_ptr> decoNew = Sci::make_unique>(indicator); decoNew->rs.InsertSpace(0, static_cast(length)); typename std::vector>>::iterator it = std::lower_bound( @@ -300,16 +300,16 @@ namespace Scintilla { std::unique_ptr DecorationCreate(bool largeDocument, int indicator) { if (largeDocument) - return std::unique_ptr>(new Decoration(indicator)); + return Sci::make_unique>(indicator); else - return std::unique_ptr>(new Decoration(indicator)); + return Sci::make_unique>(indicator); } std::unique_ptr DecorationListCreate(bool largeDocument) { if (largeDocument) - return std::unique_ptr>(new DecorationList()); + return Sci::make_unique>(); else - return std::unique_ptr>(new DecorationList()); + return Sci::make_unique>(); } } diff --git a/src/Document.cxx b/src/Document.cxx index 43751a716..b889a7d9b 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -135,11 +135,11 @@ Document::Document(int options) : matchesValid = false; - perLineData[ldMarkers].reset(new LineMarkers()); - perLineData[ldLevels].reset(new LineLevels()); - perLineData[ldState].reset(new LineState()); - perLineData[ldMargin].reset(new LineAnnotation()); - perLineData[ldAnnotation].reset(new LineAnnotation()); + perLineData[ldMarkers] = Sci::make_unique(); + perLineData[ldLevels] = Sci::make_unique(); + perLineData[ldState] = Sci::make_unique(); + perLineData[ldMargin] = Sci::make_unique(); + perLineData[ldAnnotation] = Sci::make_unique(); decorations = DecorationListCreate(IsLarge()); diff --git a/src/EditView.cxx b/src/EditView.cxx index c16f25ac6..3ae7a5d67 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -28,7 +28,6 @@ #include "ILexer.h" #include "Scintilla.h" -#include "StringCopy.h" #include "CharacterSet.h" #include "CharacterCategory.h" #include "Position.h" @@ -229,7 +228,7 @@ bool EditView::ClearTabstops(Sci::Line line) { bool EditView::AddTabstop(Sci::Line line, int x) { if (!ldTabstops) { - ldTabstops.reset(new LineTabstops()); + ldTabstops = Sci::make_unique(); } return ldTabstops && ldTabstops->AddTabstop(line, x); } @@ -287,7 +286,7 @@ static const char *ControlCharacterString(unsigned char ch) noexcept { "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" }; - if (ch < ELEMENTS(reps)) { + if (ch < Sci::size(reps)) { return reps[ch]; } else { return "BAD"; diff --git a/src/Editor.cxx b/src/Editor.cxx index f8dd2ccad..aec983f00 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -28,7 +28,6 @@ #include "ILexer.h" #include "Scintilla.h" -#include "StringCopy.h" #include "CharacterSet.h" #include "CharacterCategory.h" #include "Position.h" @@ -218,7 +217,7 @@ void Editor::SetRepresentations() { "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" }; - for (size_t j=0; j < ELEMENTS(reps); j++) { + for (size_t j=0; j < Sci::size(reps); j++) { const char c[2] = { static_cast(j), 0 }; reprs.SetRepresentation(c, reps[j]); } @@ -232,7 +231,7 @@ void Editor::SetRepresentations() { "DCS", "PU1", "PU2", "STS", "CCH", "MW", "SPA", "EPA", "SOS", "SGCI", "SCI", "CSI", "ST", "OSC", "PM", "APC" }; - for (size_t j=0; j < ELEMENTS(repsC1); j++) { + for (size_t j=0; j < Sci::size(repsC1); j++) { const char c1[3] = { '\xc2', static_cast(0x80+j), 0 }; reprs.SetRepresentation(c1, repsC1[j]); } @@ -1989,7 +1988,7 @@ void Editor::InsertCharacter(const char *s, unsigned int len, CharacterSource ch // characters representing themselves. } else { unsigned int utf32[1] = { 0 }; - UTF32FromUTF8(s, len, utf32, ELEMENTS(utf32)); + UTF32FromUTF8(s, len, utf32, Sci::size(utf32)); ch = utf32[0]; } } diff --git a/src/ExternalLexer.cxx b/src/ExternalLexer.cxx index c6a505007..acb18339d 100644 --- a/src/ExternalLexer.cxx +++ b/src/ExternalLexer.cxx @@ -191,8 +191,7 @@ void LexerManager::Load(const char *path) { if (ll->moduleName == path) return; } - LexerLibrary *lib = new LexerLibrary(path); - libraries.push_back(std::unique_ptr(lib)); + libraries.push_back(Sci::make_unique(path)); } void LexerManager::Clear() noexcept { diff --git a/src/Indicator.cxx b/src/Indicator.cxx index 5b1259fb4..1d594d214 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -16,7 +16,6 @@ #include "Platform.h" #include "Scintilla.h" -#include "StringCopy.h" #include "IntegerRectangle.h" #include "Indicator.h" #include "XPM.h" @@ -210,7 +209,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r Point(ix + pixelHeight, iy + pixelHeight), // Right Point(ix, iy) // Top }; - surface->Polygon(pts, ELEMENTS(pts), sacDraw.fore, sacDraw.fore); + surface->Polygon(pts, Sci::size(pts), sacDraw.fore, sacDraw.fore); } } else { // Either INDIC_PLAIN or unknown surface->MoveTo(irc.left, ymid); diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx index d2c906d08..e026e4a17 100644 --- a/src/LineMarker.cxx +++ b/src/LineMarker.cxx @@ -18,7 +18,6 @@ #include "Scintilla.h" -#include "StringCopy.h" #include "IntegerRectangle.h" #include "XPM.h" #include "LineMarker.h" @@ -33,11 +32,11 @@ LineMarker::LineMarker(const LineMarker &other) { backSelected = other.backSelected; alpha = other.alpha; if (other.pxpm) - pxpm.reset(new XPM(*other.pxpm)); + pxpm = Sci::make_unique(*other.pxpm); else pxpm = nullptr; if (other.image) - image.reset(new RGBAImage(*other.image)); + image = Sci::make_unique(*other.image); else image = nullptr; customDraw = other.customDraw; @@ -52,11 +51,11 @@ LineMarker &LineMarker::operator=(const LineMarker &other) { backSelected = other.backSelected; alpha = other.alpha; if (other.pxpm) - pxpm.reset(new XPM(*other.pxpm)); + pxpm = Sci::make_unique(*other.pxpm); else pxpm = nullptr; if (other.image) - image.reset(new RGBAImage(*other.image)); + image = Sci::make_unique(*other.image); else image = nullptr; customDraw = other.customDraw; @@ -65,17 +64,17 @@ LineMarker &LineMarker::operator=(const LineMarker &other) { } void LineMarker::SetXPM(const char *textForm) { - pxpm.reset(new XPM(textForm)); + pxpm = Sci::make_unique(textForm); markType = SC_MARK_PIXMAP; } void LineMarker::SetXPM(const char *const *linesForm) { - pxpm.reset(new XPM(linesForm)); + pxpm = Sci::make_unique(linesForm); markType = SC_MARK_PIXMAP; } void LineMarker::SetRGBAImage(Point sizeRGBAImage, float scale, const unsigned char *pixelsRGBAImage) { - image.reset(new RGBAImage(static_cast(sizeRGBAImage.x), static_cast(sizeRGBAImage.y), scale, pixelsRGBAImage)); + image = Sci::make_unique(static_cast(sizeRGBAImage.x), static_cast(sizeRGBAImage.y), scale, pixelsRGBAImage); markType = SC_MARK_RGBAIMAGE; } @@ -185,7 +184,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX - dimOn4, centreY + dimOn2), Point::FromInts(centreX + dimOn2 - dimOn4, centreY), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_ARROWDOWN) { Point pts[] = { @@ -193,7 +192,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX + dimOn2, centreY - dimOn4), Point::FromInts(centreX, centreY + dimOn2 - dimOn4), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_PLUS) { Point pts[] = { @@ -210,7 +209,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX - 1, centreY + 1), Point::FromInts(centreX - armSize, centreY + 1), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_MINUS) { Point pts[] = { @@ -219,7 +218,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX + armSize, centreY +1), Point::FromInts(centreX - armSize, centreY + 1), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_SMALLRECT) { PRectangle rcSmall; @@ -415,7 +414,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX, centreY + dimOn4), Point::FromInts(centreX, centreY + dimOn2), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_LEFTRECT) { PRectangle rcLeft = rcWhole; rcLeft.right = rcLeft.left + 4; @@ -429,7 +428,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(ircWhole.right - 3, centreY + halfHeight), Point::FromInts(ircWhole.left, centreY + halfHeight), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_VERTICALBOOKMARK) { const int halfWidth = minDim / 3; Point pts[] = { @@ -439,7 +438,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX, centreY + dimOn2 - halfWidth), Point::FromInts(centreX - halfWidth, centreY + dimOn2), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else { // SC_MARK_FULLRECT surface->FillRectangle(rcWhole, back); } diff --git a/src/Partitioning.h b/src/Partitioning.h index 06dc88ade..bb3320b80 100644 --- a/src/Partitioning.h +++ b/src/Partitioning.h @@ -8,6 +8,8 @@ #ifndef PARTITIONING_H #define PARTITIONING_H +#include "Compat.h" + namespace Scintilla { /// A split vector of integers with a method for adding a value to all elements @@ -85,7 +87,7 @@ private: } void Allocate(ptrdiff_t growSize) { - body.reset(new SplitVectorWithRangeAdd(growSize)); + body = Sci::make_unique>(growSize); stepPartition = 0; stepLength = 0; body->Insert(0, 0); // This value stays 0 for ever 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(); diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index a1f71fdae..5a6d8dac0 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -74,11 +74,11 @@ LineLayout::~LineLayout() { void LineLayout::Resize(int maxLineLength_) { if (maxLineLength_ > maxLineLength) { Free(); - chars.reset(new char[maxLineLength_ + 1]); - styles.reset(new unsigned char[maxLineLength_ + 1]); + chars = Sci::make_unique(maxLineLength_ + 1); + styles = Sci::make_unique(maxLineLength_ + 1); // Extra position allocated as sometimes the Windows // GetTextExtentExPoint API writes an extra element. - positions.reset(new XYPOSITION[maxLineLength_ + 1 + 1]); + positions = Sci::make_unique(maxLineLength_ + 1 + 1); maxLineLength = maxLineLength_; } } @@ -126,15 +126,15 @@ bool LineLayout::InLine(int offset, int line) const { void LineLayout::SetLineStart(int line, int start) { if ((line >= lenLineStarts) && (line != 0)) { - int newMaxLines = line + 20; - int *newLineStarts = new int[newMaxLines]; + const int newMaxLines = line + 20; + std::unique_ptr newLineStarts = Sci::make_unique(newMaxLines); for (int i = 0; i < newMaxLines; i++) { if (i < lenLineStarts) newLineStarts[i] = lineStarts[i]; else newLineStarts[i] = 0; } - lineStarts.reset(newLineStarts); + lineStarts = std::move(newLineStarts); lenLineStarts = newMaxLines; } lineStarts[line] = start; @@ -341,7 +341,7 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret, } } if (!cache[pos]) { - cache[pos].reset(new LineLayout(maxChars)); + cache[pos] = Sci::make_unique(maxChars); } cache[pos]->lineNumber = lineNumber; cache[pos]->inCache = true; @@ -570,7 +570,7 @@ PositionCacheEntry::PositionCacheEntry(const PositionCacheEntry &other) : styleNumber(other.styleNumber), len(other.styleNumber), clock(other.styleNumber), positions(nullptr) { if (other.positions) { const size_t lenData = len + (len / sizeof(XYPOSITION)) + 1; - positions.reset(new XYPOSITION[lenData]); + positions = Sci::make_unique(lenData); memcpy(positions.get(), other.positions.get(), lenData * sizeof(XYPOSITION)); } } @@ -582,7 +582,7 @@ void PositionCacheEntry::Set(unsigned int styleNumber_, const char *s_, len = len_; clock = clock_; if (s_ && positions_) { - positions.reset(new XYPOSITION[len + (len / sizeof(XYPOSITION)) + 1]); + positions = Sci::make_unique(len + (len / sizeof(XYPOSITION)) + 1); for (unsigned int i=0; i::RemoveRunIfSameAsPrevious(DISTANCE run) { template RunStyles::RunStyles() { - starts.reset(new Partitioning(8)); - styles.reset(new SplitVector