diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CellBuffer.cxx | 2 | ||||
-rw-r--r-- | src/ContractionState.cxx | 10 | ||||
-rw-r--r-- | src/Decoration.cxx | 2 | ||||
-rw-r--r-- | src/Document.cxx | 10 | ||||
-rw-r--r-- | src/EditView.cxx | 2 | ||||
-rw-r--r-- | src/ExternalLexer.cxx | 5 | ||||
-rw-r--r-- | src/LineMarker.cxx | 6 | ||||
-rw-r--r-- | src/Partitioning.h | 2 | ||||
-rw-r--r-- | src/PerLine.cxx | 25 | ||||
-rw-r--r-- | src/PositionCache.cxx | 18 | ||||
-rw-r--r-- | src/RunStyles.cxx | 8 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 2 |
12 files changed, 46 insertions, 46 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 513c9a9b8..b4a4029f6 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -97,7 +97,7 @@ void Action::Create(actionType at_, Sci::Position position_, const char *data_, position = position_; at = at_; if (lenData_) { - data = std::unique_ptr<char []>(new char[lenData_]); + data = std::make_unique<char[]>(lenData_); memcpy(&data[0], data_, lenData_); } lenData = lenData_; diff --git a/src/ContractionState.cxx b/src/ContractionState.cxx index 8777e4af9..77b717a17 100644 --- a/src/ContractionState.cxx +++ b/src/ContractionState.cxx @@ -35,11 +35,11 @@ ContractionState::~ContractionState() { void ContractionState::EnsureData() { if (OneToOne()) { - visible.reset(new RunStyles<int, int>()); - expanded.reset(new RunStyles<int, int>()); - heights.reset(new RunStyles<int, int>()); - foldDisplayTexts.reset(new SparseVector<UniqueString>()); - displayLines.reset(new Partitioning<int>(4)); + visible = std::make_unique<RunStyles<int, int>>(); + expanded = std::make_unique<RunStyles<int, int>>(); + heights = std::make_unique<RunStyles<int, int>>(); + foldDisplayTexts = std::make_unique<SparseVector<UniqueString>>(); + displayLines = std::make_unique<Partitioning<int>>(4); InsertLines(0, linesInDocument); } } diff --git a/src/Decoration.cxx b/src/Decoration.cxx index bca2d6cb0..a9e22adda 100644 --- a/src/Decoration.cxx +++ b/src/Decoration.cxx @@ -55,7 +55,7 @@ Decoration *DecorationList::DecorationFromIndicator(int indicator) { Decoration *DecorationList::Create(int indicator, int length) { currentIndicator = indicator; - std::unique_ptr<Decoration> decoNew(new Decoration(indicator)); + std::unique_ptr<Decoration> decoNew = std::make_unique<Decoration>(indicator); decoNew->rs.InsertSpace(0, length); std::vector<std::unique_ptr<Decoration>>::iterator it = std::lower_bound( diff --git a/src/Document.cxx b/src/Document.cxx index a6f408f3e..41d6b2375 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -118,11 +118,11 @@ Document::Document(int options) : UTF8BytesOfLeadInitialise(); - 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] = std::make_unique<LineMarkers>(); + perLineData[ldLevels] = std::make_unique<LineLevels>(); + perLineData[ldState] = std::make_unique<LineState>(); + perLineData[ldMargin] = std::make_unique<LineAnnotation>(); + perLineData[ldAnnotation] = std::make_unique<LineAnnotation>(); cb.SetPerLine(this); } diff --git a/src/EditView.cxx b/src/EditView.cxx index 8db21d5d9..d4cdf4dc8 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -227,7 +227,7 @@ bool EditView::ClearTabstops(Sci::Line line) { bool EditView::AddTabstop(Sci::Line line, int x) { if (!ldTabstops) { - ldTabstops.reset(new LineTabstops()); + ldTabstops = std::make_unique<LineTabstops>(); } LineTabstops *lt = static_cast<LineTabstops *>(ldTabstops.get()); return lt && lt->AddTabstop(line, x); diff --git a/src/ExternalLexer.cxx b/src/ExternalLexer.cxx index fdef2ad57..1ab96913a 100644 --- a/src/ExternalLexer.cxx +++ b/src/ExternalLexer.cxx @@ -65,6 +65,8 @@ LexerLibrary::LexerLibrary(const char *moduleName_) { char lexname[100] = ""; GetLexerName(i, lexname, sizeof(lexname)); ExternalLexerModule *lex = new ExternalLexerModule(SCLEX_AUTOMATIC, NULL, lexname, NULL); + // This is storing a second reference to lex in the Catalogue as well as in modules. + // TODO: Should use std::shared_ptr or similar to ensure allocation safety. Catalogue::AddLexerModule(lex); // Remember ExternalLexerModule so we don't leak it @@ -112,8 +114,7 @@ void LexerManager::Load(const char *path) { if (ll->moduleName == path) return; } - LexerLibrary *lib = new LexerLibrary(path); - libraries.push_back(std::unique_ptr<LexerLibrary>(lib)); + libraries.push_back(std::make_unique<LexerLibrary>(path)); } void LexerManager::Clear() { diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx index f556e77f8..e3c2c6713 100644 --- a/src/LineMarker.cxx +++ b/src/LineMarker.cxx @@ -25,17 +25,17 @@ using namespace Scintilla; void LineMarker::SetXPM(const char *textForm) { - pxpm.reset(new XPM(textForm)); + pxpm = std::make_unique<XPM>(textForm); markType = SC_MARK_PIXMAP; } void LineMarker::SetXPM(const char *const *linesForm) { - pxpm.reset(new XPM(linesForm)); + pxpm = std::make_unique<XPM>(linesForm); markType = SC_MARK_PIXMAP; } void LineMarker::SetRGBAImage(Point sizeRGBAImage, float scale, const unsigned char *pixelsRGBAImage) { - image.reset(new RGBAImage(static_cast<int>(sizeRGBAImage.x), static_cast<int>(sizeRGBAImage.y), scale, pixelsRGBAImage)); + image = std::make_unique<RGBAImage>(static_cast<int>(sizeRGBAImage.x), static_cast<int>(sizeRGBAImage.y), scale, pixelsRGBAImage); markType = SC_MARK_RGBAIMAGE; } diff --git a/src/Partitioning.h b/src/Partitioning.h index 112a543ca..57c8656c8 100644 --- a/src/Partitioning.h +++ b/src/Partitioning.h @@ -83,7 +83,7 @@ private: } void Allocate(ptrdiff_t growSize) { - body.reset(new SplitVectorWithRangeAdd<T>(growSize)); + body = std::make_unique<SplitVectorWithRangeAdd<T>>(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 2afbf3161..6785ef81b 100644 --- a/src/PerLine.cxx +++ b/src/PerLine.cxx @@ -119,7 +119,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] = std::make_unique<MarkerHandleSet>(); markers[line]->CombineWith(markers[line + 1].get()); markers[line + 1].reset(); } @@ -155,7 +155,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] = std::make_unique<MarkerHandleSet>(); } markers[line]->InsertHandle(handleCurrent, markerNum); @@ -359,17 +359,16 @@ const unsigned char *LineAnnotation::Styles(Sci::Line line) const { return 0; } -static char *AllocateAnnotation(int length, int style) { +static std::unique_ptr<char[]>AllocateAnnotation(int length, int style) { const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0); - char *ret = new char[len](); - return ret; + return std::make_unique<char[]>(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<int>(strlen(text)), style)); + annotations[line] = AllocateAnnotation(static_cast<int>(strlen(text)), style); char *pa = annotations[line].get(); assert(pa); AnnotationHeader *pah = reinterpret_cast<AnnotationHeader *>(pa); @@ -391,7 +390,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<AnnotationHeader *>(annotations[line].get())->style = static_cast<short>(style); } @@ -400,16 +399,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 { AnnotationHeader *pahSource = reinterpret_cast<AnnotationHeader *>(annotations[line].get()); if (pahSource->style != IndividualStyles) { - char *allocation = AllocateAnnotation(pahSource->length, IndividualStyles); - AnnotationHeader *pahAlloc = reinterpret_cast<AnnotationHeader *>(allocation); + std::unique_ptr<char[]>allocation = AllocateAnnotation(pahSource->length, IndividualStyles); + AnnotationHeader *pahAlloc = reinterpret_cast<AnnotationHeader *>(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<AnnotationHeader *>(annotations[line].get()); @@ -468,7 +467,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] = std::make_unique<TabstopList>(); } TabstopList *tl = tabstops[line].get(); diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 99e3c4d56..273875e4e 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 = std::make_unique<char[]>(maxLineLength_ + 1); + styles = std::make_unique<unsigned char []>(maxLineLength_ + 1); // Extra position allocated as sometimes the Windows // GetTextExtentExPoint API writes an extra element. - positions.reset(new XYPOSITION[maxLineLength_ + 1 + 1]); + positions = std::make_unique<XYPOSITION []>(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<int[]> newLineStarts = std::make_unique<int[]>(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; @@ -339,7 +339,7 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret, } } if (!cache[pos]) { - cache[pos].reset(new LineLayout(maxChars)); + cache[pos] = std::make_unique<LineLayout>(maxChars); } cache[pos]->lineNumber = lineNumber; cache[pos]->inCache = true; @@ -557,7 +557,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 = std::make_unique<XYPOSITION[]>(lenData); memcpy(positions.get(), other.positions.get(), lenData * sizeof(XYPOSITION)); } } @@ -569,7 +569,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 = std::make_unique<XYPOSITION[]>(len + (len / sizeof(XYPOSITION)) + 1); for (unsigned int i=0; i<len; i++) { positions[i] = positions_[i]; } diff --git a/src/RunStyles.cxx b/src/RunStyles.cxx index f3939bbd2..6dbfb4c4b 100644 --- a/src/RunStyles.cxx +++ b/src/RunStyles.cxx @@ -76,8 +76,8 @@ void RunStyles<DISTANCE, STYLE>::RemoveRunIfSameAsPrevious(DISTANCE run) { template <typename DISTANCE, typename STYLE> RunStyles<DISTANCE, STYLE>::RunStyles() { - starts.reset(new Partitioning<DISTANCE>(8)); - styles.reset(new SplitVector<STYLE>()); + starts = std::make_unique<Partitioning<DISTANCE>>(8); + styles = std::make_unique<SplitVector<STYLE>>(); styles->InsertValue(0, 2, 0); } @@ -212,8 +212,8 @@ void RunStyles<DISTANCE, STYLE>::InsertSpace(DISTANCE position, DISTANCE insertL template <typename DISTANCE, typename STYLE> void RunStyles<DISTANCE, STYLE>::DeleteAll() { - starts.reset(new Partitioning<DISTANCE>(8)); - styles.reset(new SplitVector<STYLE>()); + starts = std::make_unique<Partitioning<DISTANCE>>(8); + styles = std::make_unique<SplitVector<STYLE>>(); styles->InsertValue(0, 2, 0); } diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index d83505d40..1c4f6d690 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -586,7 +586,7 @@ void ViewStyle::CreateAndAddFont(const FontSpecification &fs) { if (fs.fontName) { FontMap::iterator it = fonts.find(fs); if (it == fonts.end()) { - fonts[fs] = std::unique_ptr<FontRealised>(new FontRealised()); + fonts[fs] = std::make_unique<FontRealised>(); } } } |