diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Document.cxx | 101 | ||||
| -rw-r--r-- | src/Document.h | 17 | ||||
| -rw-r--r-- | src/EditView.cxx | 16 | ||||
| -rw-r--r-- | src/Partitioning.h | 10 | ||||
| -rw-r--r-- | src/PositionCache.cxx | 58 | ||||
| -rw-r--r-- | src/PositionCache.h | 12 | ||||
| -rw-r--r-- | src/RunStyles.cxx | 16 | ||||
| -rw-r--r-- | src/RunStyles.h | 4 | ||||
| -rw-r--r-- | src/SparseVector.h | 14 | 
9 files changed, 122 insertions, 126 deletions
| diff --git a/src/Document.cxx b/src/Document.cxx index 22987edfb..0e315bdb9 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -120,11 +120,11 @@ Document::Document() {  	UTF8BytesOfLeadInitialise(); -	perLineData[ldMarkers] = new LineMarkers(); -	perLineData[ldLevels] = new LineLevels(); -	perLineData[ldState] = new LineState(); -	perLineData[ldMargin] = new LineAnnotation(); -	perLineData[ldAnnotation] = new LineAnnotation(); +	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());  	cb.SetPerLine(this);  } @@ -133,19 +133,35 @@ Document::~Document() {  	for (const WatcherWithUserData &watcher : watchers) {  		watcher.watcher->NotifyDeleted(this, watcher.userData);  	} -	for (PerLine *&pl : perLineData) { -		delete pl; -		pl = nullptr; -	}  }  void Document::Init() { -	for (PerLine *pl : perLineData) { +	for (const std::unique_ptr<PerLine> &pl : perLineData) {  		if (pl)  			pl->Init();  	}  } +LineMarkers *Document::Markers() const { +	return static_cast<LineMarkers *>(perLineData[ldMarkers].get()); +} + +LineLevels *Document::Levels() const { +	return static_cast<LineLevels *>(perLineData[ldLevels].get()); +} + +LineState *Document::States() const { +	return static_cast<LineState *>(perLineData[ldState].get()); +} + +LineAnnotation *Document::Margins() const { +	return static_cast<LineAnnotation *>(perLineData[ldMargin].get()); +} + +LineAnnotation *Document::Annotations() const { +	return static_cast<LineAnnotation *>(perLineData[ldAnnotation].get()); +} +  int Document::LineEndTypesSupported() const {  	if ((SC_CP_UTF8 == dbcsCodePage) && pli)  		return pli->LineEndTypesSupported(); @@ -181,14 +197,14 @@ bool Document::SetLineEndTypesAllowed(int lineEndBitSet_) {  }  void Document::InsertLine(Sci::Line line) { -	for (PerLine *pl : perLineData) { +	for (const std::unique_ptr<PerLine> &pl : perLineData) {  		if (pl)  			pl->InsertLine(line);  	}  }  void Document::RemoveLine(Sci::Line line) { -	for (PerLine *pl : perLineData) { +	for (const std::unique_ptr<PerLine> &pl : perLineData) {  		if (pl)  			pl->RemoveLine(line);  	} @@ -274,18 +290,17 @@ void Document::TentativeUndo() {  	}  } -int Document::GetMark(Sci::Line line) { -	return static_cast<LineMarkers *>(perLineData[ldMarkers])->MarkValue(line); +int Document::GetMark(Sci::Line line) const { +	return Markers()->MarkValue(line);  }  Sci::Line Document::MarkerNext(Sci::Line lineStart, int mask) const { -	return static_cast<LineMarkers *>(perLineData[ldMarkers])->MarkerNext(lineStart, mask); +	return Markers()->MarkerNext(lineStart, mask);  }  int Document::AddMark(Sci::Line line, int markerNum) {  	if (line >= 0 && line <= LinesTotal()) { -		const int prev = static_cast<LineMarkers *>(perLineData[ldMarkers])-> -			AddMark(line, markerNum, LinesTotal()); +		const int prev = Markers()->AddMark(line, markerNum, LinesTotal());  		DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line);  		NotifyModified(mh);  		return prev; @@ -299,22 +314,22 @@ void Document::AddMarkSet(Sci::Line line, int valueSet) {  		return;  	}  	unsigned int m = valueSet; -	for (int i = 0; m; i++, m >>= 1) +	for (int i = 0; m; i++, m >>= 1) {  		if (m & 1) -			static_cast<LineMarkers *>(perLineData[ldMarkers])-> -				AddMark(line, i, LinesTotal()); +			Markers()->AddMark(line, i, LinesTotal()); +	}  	DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line);  	NotifyModified(mh);  }  void Document::DeleteMark(Sci::Line line, int markerNum) { -	static_cast<LineMarkers *>(perLineData[ldMarkers])->DeleteMark(line, markerNum, false); +	Markers()->DeleteMark(line, markerNum, false);  	DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line);  	NotifyModified(mh);  }  void Document::DeleteMarkFromHandle(int markerHandle) { -	static_cast<LineMarkers *>(perLineData[ldMarkers])->DeleteMarkFromHandle(markerHandle); +	Markers()->DeleteMarkFromHandle(markerHandle);  	DocModification mh(SC_MOD_CHANGEMARKER, 0, 0, 0, 0);  	mh.line = -1;  	NotifyModified(mh); @@ -323,7 +338,7 @@ void Document::DeleteMarkFromHandle(int markerHandle) {  void Document::DeleteAllMarks(int markerNum) {  	bool someChanges = false;  	for (Sci::Line line = 0; line < LinesTotal(); line++) { -		if (static_cast<LineMarkers *>(perLineData[ldMarkers])->DeleteMark(line, markerNum, true)) +		if (Markers()->DeleteMark(line, markerNum, true))  			someChanges = true;  	}  	if (someChanges) { @@ -333,8 +348,8 @@ void Document::DeleteAllMarks(int markerNum) {  	}  } -Sci::Line Document::LineFromHandle(int markerHandle) { -	return static_cast<LineMarkers *>(perLineData[ldMarkers])->LineFromHandle(markerHandle); +Sci::Line Document::LineFromHandle(int markerHandle) const { +	return Markers()->LineFromHandle(markerHandle);  }  Sci_Position SCI_METHOD Document::LineStart(Sci_Position line) const { @@ -409,7 +424,7 @@ Sci::Position Document::VCHomePosition(Sci::Position position) const {  }  int SCI_METHOD Document::SetLevel(Sci_Position line, int level) { -	const int prev = static_cast<LineLevels *>(perLineData[ldLevels])->SetLevel(line, level, LinesTotal()); +	const int prev = Levels()->SetLevel(line, level, LinesTotal());  	if (prev != level) {  		DocModification mh(SC_MOD_CHANGEFOLD | SC_MOD_CHANGEMARKER,  		                   LineStart(line), 0, 0, 0, line); @@ -421,11 +436,11 @@ int SCI_METHOD Document::SetLevel(Sci_Position line, int level) {  }  int SCI_METHOD Document::GetLevel(Sci_Position line) const { -	return static_cast<LineLevels *>(perLineData[ldLevels])->GetLevel(line); +	return Levels()->GetLevel(line);  }  void Document::ClearLevels() { -	static_cast<LineLevels *>(perLineData[ldLevels])->ClearLevels(); +	Levels()->ClearLevels();  }  static bool IsSubordinate(int levelStart, int levelTry) { @@ -2123,7 +2138,7 @@ void Document::SetLexInterface(LexInterface *pLexInterface) {  }  int SCI_METHOD Document::SetLineState(Sci_Position line, int state) { -	const int statePrevious = static_cast<LineState *>(perLineData[ldState])->SetLineState(line, state); +	const int statePrevious = States()->SetLineState(line, state);  	if (state != statePrevious) {  		DocModification mh(SC_MOD_CHANGELINESTATE, LineStart(line), 0, 0, 0, line);  		NotifyModified(mh); @@ -2132,11 +2147,11 @@ int SCI_METHOD Document::SetLineState(Sci_Position line, int state) {  }  int SCI_METHOD Document::GetLineState(Sci_Position line) const { -	return static_cast<LineState *>(perLineData[ldState])->GetLineState(line); +	return States()->GetLineState(line);  } -Sci::Line Document::GetMaxLineState() { -	return static_cast<LineState *>(perLineData[ldState])->GetMaxLineState(); +Sci::Line Document::GetMaxLineState() const { +	return States()->GetMaxLineState();  }  void SCI_METHOD Document::ChangeLexerState(Sci_Position start, Sci_Position end) { @@ -2145,24 +2160,24 @@ void SCI_METHOD Document::ChangeLexerState(Sci_Position start, Sci_Position end)  }  StyledText Document::MarginStyledText(Sci::Line line) const { -	const LineAnnotation *pla = static_cast<LineAnnotation *>(perLineData[ldMargin]); +	const LineAnnotation *pla = Margins();  	return StyledText(pla->Length(line), pla->Text(line),  		pla->MultipleStyles(line), pla->Style(line), pla->Styles(line));  }  void Document::MarginSetText(Sci::Line line, const char *text) { -	static_cast<LineAnnotation *>(perLineData[ldMargin])->SetText(line, text); +	Margins()->SetText(line, text);  	DocModification mh(SC_MOD_CHANGEMARGIN, LineStart(line), 0, 0, 0, line);  	NotifyModified(mh);  }  void Document::MarginSetStyle(Sci::Line line, int style) { -	static_cast<LineAnnotation *>(perLineData[ldMargin])->SetStyle(line, style); +	Margins()->SetStyle(line, style);  	NotifyModified(DocModification(SC_MOD_CHANGEMARGIN, LineStart(line), 0, 0, 0, line));  }  void Document::MarginSetStyles(Sci::Line line, const unsigned char *styles) { -	static_cast<LineAnnotation *>(perLineData[ldMargin])->SetStyles(line, styles); +	Margins()->SetStyles(line, styles);  	NotifyModified(DocModification(SC_MOD_CHANGEMARGIN, LineStart(line), 0, 0, 0, line));  } @@ -2171,11 +2186,11 @@ void Document::MarginClearAll() {  	for (Sci::Line l=0; l<maxEditorLine; l++)  		MarginSetText(l, 0);  	// Free remaining data -	static_cast<LineAnnotation *>(perLineData[ldMargin])->ClearAll(); +	Margins()->ClearAll();  }  StyledText Document::AnnotationStyledText(Sci::Line line) const { -	const LineAnnotation *pla = static_cast<LineAnnotation *>(perLineData[ldAnnotation]); +	const LineAnnotation *pla = Annotations();  	return StyledText(pla->Length(line), pla->Text(line),  		pla->MultipleStyles(line), pla->Style(line), pla->Styles(line));  } @@ -2183,7 +2198,7 @@ StyledText Document::AnnotationStyledText(Sci::Line line) const {  void Document::AnnotationSetText(Sci::Line line, const char *text) {  	if (line >= 0 && line < LinesTotal()) {  		const Sci::Line linesBefore = AnnotationLines(line); -		static_cast<LineAnnotation *>(perLineData[ldAnnotation])->SetText(line, text); +		Annotations()->SetText(line, text);  		const int linesAfter = AnnotationLines(line);  		DocModification mh(SC_MOD_CHANGEANNOTATION, LineStart(line), 0, 0, 0, line);  		mh.annotationLinesAdded = linesAfter - linesBefore; @@ -2192,19 +2207,19 @@ void Document::AnnotationSetText(Sci::Line line, const char *text) {  }  void Document::AnnotationSetStyle(Sci::Line line, int style) { -	static_cast<LineAnnotation *>(perLineData[ldAnnotation])->SetStyle(line, style); +	Annotations()->SetStyle(line, style);  	DocModification mh(SC_MOD_CHANGEANNOTATION, LineStart(line), 0, 0, 0, line);  	NotifyModified(mh);  }  void Document::AnnotationSetStyles(Sci::Line line, const unsigned char *styles) {  	if (line >= 0 && line < LinesTotal()) { -		static_cast<LineAnnotation *>(perLineData[ldAnnotation])->SetStyles(line, styles); +		Annotations()->SetStyles(line, styles);  	}  }  int Document::AnnotationLines(Sci::Line line) const { -	return static_cast<LineAnnotation *>(perLineData[ldAnnotation])->Lines(line); +	return Annotations()->Lines(line);  }  void Document::AnnotationClearAll() { @@ -2212,7 +2227,7 @@ void Document::AnnotationClearAll() {  	for (Sci::Line l=0; l<maxEditorLine; l++)  		AnnotationSetText(l, 0);  	// Free remaining data -	static_cast<LineAnnotation *>(perLineData[ldAnnotation])->ClearAll(); +	Annotations()->ClearAll();  }  void Document::IncrementStyleClock() { diff --git a/src/Document.h b/src/Document.h index 77686f78c..025b010ec 100644 --- a/src/Document.h +++ b/src/Document.h @@ -163,6 +163,10 @@ public:  };  class Document; +class LineMarkers; +class LineLevels; +class LineState; +class LineAnnotation;  inline int LevelNumber(int level) {  	return level & SC_FOLDLEVELNUMBERMASK; @@ -224,7 +228,12 @@ private:  	// ldSize is not real data - it is for dimensions and loops  	enum lineData { ldMarkers, ldLevels, ldState, ldMargin, ldAnnotation, ldSize }; -	PerLine *perLineData[ldSize]; +	std::unique_ptr<PerLine> perLineData[ldSize]; +	LineMarkers *Markers() const; +	LineLevels *Levels() const; +	LineState *States() const; +	LineAnnotation *Margins() const; +	LineAnnotation *Annotations() const;  	bool matchesValid;  	std::unique_ptr<RegexSearchBase> regex; @@ -358,14 +367,14 @@ public:  	void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const {  		cb.GetStyleRange(buffer, position, lengthRetrieve);  	} -	int GetMark(Sci::Line line); +	int GetMark(Sci::Line line) const;  	Sci::Line MarkerNext(Sci::Line lineStart, int mask) const;  	int AddMark(Sci::Line line, int markerNum);  	void AddMarkSet(Sci::Line line, int valueSet);  	void DeleteMark(Sci::Line line, int markerNum);  	void DeleteMarkFromHandle(int markerHandle);  	void DeleteAllMarks(int markerNum); -	Sci::Line LineFromHandle(int markerHandle); +	Sci::Line LineFromHandle(int markerHandle) const;  	Sci_Position SCI_METHOD LineStart(Sci_Position line) const;  	bool IsLineStartPosition(Sci::Position position) const;  	Sci_Position SCI_METHOD LineEnd(Sci_Position line) const; @@ -419,7 +428,7 @@ public:  	int SCI_METHOD SetLineState(Sci_Position line, int state);  	int SCI_METHOD GetLineState(Sci_Position line) const; -	Sci::Line GetMaxLineState(); +	Sci::Line GetMaxLineState() const;  	void SCI_METHOD ChangeLexerState(Sci_Position start, Sci_Position end);  	StyledText MarginStyledText(Sci::Line line) const; diff --git a/src/EditView.cxx b/src/EditView.cxx index d1ebc345a..2798bb25f 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -423,8 +423,8 @@ void EditView::LayoutLine(const EditModel &model, Sci::Line line, Surface *surfa  		// Fill base line layout  		const int lineLength = posLineEnd - posLineStart; -		model.pdoc->GetCharRange(ll->chars, posLineStart, lineLength); -		model.pdoc->GetStyleRange(ll->styles, posLineStart, lineLength); +		model.pdoc->GetCharRange(ll->chars.get(), posLineStart, lineLength); +		model.pdoc->GetStyleRange(ll->styles.get(), posLineStart, lineLength);  		const int numCharsBeforeEOL = model.pdoc->LineEnd(line) - posLineStart;  		const int numCharsInLine = (vstyle.viewEOL) ? lineLength : numCharsBeforeEOL;  		for (Sci::Position styleInLine = 0; styleInLine < numCharsInLine; styleInLine++) { @@ -487,8 +487,8 @@ void EditView::LayoutLine(const EditModel &model, Sci::Line line, Surface *surfa  						// Over half the segments are single characters and of these about half are space characters.  						ll->positions[ts.start + 1] = vstyle.styles[ll->styles[ts.start]].spaceWidth;  					} else { -						posCache.MeasureWidths(surface, vstyle, ll->styles[ts.start], ll->chars + ts.start, -							ts.length, ll->positions + ts.start + 1, model.pdoc); +						posCache.MeasureWidths(surface, vstyle, ll->styles[ts.start], &ll->chars[ts.start], +							ts.length, &ll->positions[ts.start + 1], model.pdoc);  					}  				}  				lastSegItalics = (!ts.representation) && ((ll->chars[ts.end() - 1] != ' ') && vstyle.styles[ll->styles[ts.start]].italic); @@ -920,7 +920,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle  			if (UTF8IsAscii(chEOL)) {  				ctrlChar = ControlCharacterString(chEOL);  			} else { -				const Representation *repr = model.reprs.RepresentationFromCharacter(ll->chars + eolPos, ll->numCharsInLine - eolPos); +				const Representation *repr = model.reprs.RepresentationFromCharacter(&ll->chars[eolPos], ll->numCharsInLine - eolPos);  				if (repr) {  					ctrlChar = repr->stringRep.c_str();  					eolPos = ll->numCharsInLine; @@ -1303,7 +1303,7 @@ static void DrawBlockCaret(Surface *surface, const EditModel &model, const ViewS  	int styleMain = ll->styles[offsetFirstChar];  	FontAlias fontText = vsDraw.styles[styleMain].font;  	surface->DrawTextClipped(rcCaret, fontText, -		rcCaret.top + vsDraw.maxAscent, ll->chars + offsetFirstChar, +		rcCaret.top + vsDraw.maxAscent, &ll->chars[offsetFirstChar],  		numCharsToDraw, vsDraw.styles[styleMain].back,  		caretColour);  } @@ -1738,11 +1738,11 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi  				if (vsDraw.styles[styleMain].visible) {  					if (phasesDraw != phasesOne) {  						surface->DrawTextTransparent(rcSegment, textFont, -							rcSegment.top + vsDraw.maxAscent, ll->chars + ts.start, +							rcSegment.top + vsDraw.maxAscent, &ll->chars[ts.start],  							i - ts.start + 1, textFore);  					} else {  						surface->DrawTextNoClip(rcSegment, textFont, -							rcSegment.top + vsDraw.maxAscent, ll->chars + ts.start, +							rcSegment.top + vsDraw.maxAscent, &ll->chars[ts.start],  							i - ts.start + 1, textFore, textBack);  					}  				} diff --git a/src/Partitioning.h b/src/Partitioning.h index 726b7fcdb..968220db7 100644 --- a/src/Partitioning.h +++ b/src/Partitioning.h @@ -60,7 +60,7 @@ private:  	// there may be a step somewhere in the list.  	int stepPartition;  	int stepLength; -	SplitVectorWithRangeAdd *body; +	std::unique_ptr<SplitVectorWithRangeAdd> body;  	// Move step forward  	void ApplyStep(int partitionUpTo) { @@ -83,7 +83,7 @@ private:  	}  	void Allocate(int growSize) { -		body = new SplitVectorWithRangeAdd(growSize); +		body.reset(new SplitVectorWithRangeAdd(growSize));  		stepPartition = 0;  		stepLength = 0;  		body->Insert(0, 0);	// This value stays 0 for ever @@ -100,8 +100,6 @@ public:  	void operator=(const Partitioning &) = delete;  	~Partitioning() { -		delete body; -		body = 0;  	}  	int Partitions() const { @@ -191,9 +189,7 @@ public:  	}  	void DeleteAll() { -		int growSize = body->GetGrowSize(); -		delete body; -		Allocate(growSize); +		Allocate(body->GetGrowSize());  	}  }; diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index c302f8581..b6e6c375c 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -46,7 +46,6 @@ using namespace Scintilla;  #endif  LineLayout::LineLayout(int maxLineLength_) : -	lineStarts(0),  	lenLineStarts(0),  	lineNumber(-1),  	inCache(false), @@ -58,9 +57,6 @@ LineLayout::LineLayout(int maxLineLength_) :  	highlightColumn(false),  	containsCaret(false),  	edgeColumn(0), -	chars(0), -	styles(0), -	positions(0),  	hotspot(0,0),  	widthLine(wrapWidthInfinite),  	lines(1), @@ -77,24 +73,20 @@ LineLayout::~LineLayout() {  void LineLayout::Resize(int maxLineLength_) {  	if (maxLineLength_ > maxLineLength) {  		Free(); -		chars = new char[maxLineLength_ + 1]; -		styles = new unsigned char[maxLineLength_ + 1]; +		chars.reset(new char[maxLineLength_ + 1]); +		styles.reset(new unsigned char[maxLineLength_ + 1]);  		// Extra position allocated as sometimes the Windows  		// GetTextExtentExPoint API writes an extra element. -		positions = new XYPOSITION[maxLineLength_ + 1 + 1]; +		positions.reset(new XYPOSITION[maxLineLength_ + 1 + 1]);  		maxLineLength = maxLineLength_;  	}  }  void LineLayout::Free() { -	delete []chars; -	chars = 0; -	delete []styles; -	styles = 0; -	delete []positions; -	positions = 0; -	delete []lineStarts; -	lineStarts = 0; +	chars.reset(); +	styles.reset(); +	positions.reset(); +	lineStarts.reset();  }  void LineLayout::Invalidate(validLevel validity_) { @@ -141,8 +133,7 @@ void LineLayout::SetLineStart(int line, int start) {  			else  				newLineStarts[i] = 0;  		} -		delete []lineStarts; -		lineStarts = newLineStarts; +		lineStarts.reset(newLineStarts);  		lenLineStarts = newMaxLines;  	}  	lineStarts[line] = start; @@ -282,8 +273,7 @@ void LineLayoutCache::AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesI  	} else {  		if (lengthForLevel < cache.size()) {  			for (size_t i = lengthForLevel; i < cache.size(); i++) { -				delete cache[i]; -				cache[i] = 0; +				cache[i].reset();  			}  		}  		cache.resize(lengthForLevel); @@ -293,14 +283,12 @@ void LineLayoutCache::AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesI  void LineLayoutCache::Deallocate() {  	PLATFORM_ASSERT(useCount == 0); -	for (LineLayout *ll : cache) -		delete ll;  	cache.clear();  }  void LineLayoutCache::Invalidate(LineLayout::validLevel validity_) {  	if (!cache.empty() && !allInvalidated) { -		for (LineLayout *ll : cache) { +		for (const std::unique_ptr<LineLayout> &ll : cache) {  			if (ll) {  				ll->Invalidate(validity_);  			} @@ -346,16 +334,15 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret,  			if (cache[pos]) {  				if ((cache[pos]->lineNumber != lineNumber) ||  				        (cache[pos]->maxLineLength < maxChars)) { -					delete cache[pos]; -					cache[pos] = 0; +					cache[pos].reset();  				}  			}  			if (!cache[pos]) { -				cache[pos] = new LineLayout(maxChars); +				cache[pos].reset(new LineLayout(maxChars));  			}  			cache[pos]->lineNumber = lineNumber;  			cache[pos]->inCache = true; -			ret = cache[pos]; +			ret = cache[pos].get();  			useCount++;  		}  	} @@ -507,10 +494,10 @@ TextSegment BreakFinder::Next() {  		while (nextBreak < lineRange.end) {  			int charWidth = 1;  			if (encodingFamily == efUnicode) -				charWidth = UTF8DrawBytes(reinterpret_cast<unsigned char *>(ll->chars) + nextBreak, lineRange.end - nextBreak); +				charWidth = UTF8DrawBytes(reinterpret_cast<unsigned char *>(&ll->chars[nextBreak]), lineRange.end - nextBreak);  			else if (encodingFamily == efDBCS)  				charWidth = pdoc->IsDBCSLeadByte(ll->chars[nextBreak]) ? 2 : 1; -			const Representation *repr = preprs->RepresentationFromCharacter(ll->chars + nextBreak, charWidth); +			const Representation *repr = preprs->RepresentationFromCharacter(&ll->chars[nextBreak], charWidth);  			if (((nextBreak > 0) && (ll->styles[nextBreak] != ll->styles[nextBreak - 1])) ||  					repr ||  					(nextBreak == saeNext)) { @@ -546,7 +533,7 @@ TextSegment BreakFinder::Next() {  		subBreak = -1;  		return TextSegment(startSegment, nextBreak - startSegment);  	} else { -		subBreak += pdoc->SafeSegment(ll->chars + subBreak, nextBreak-subBreak, lengthEachSubdivision); +		subBreak += pdoc->SafeSegment(&ll->chars[subBreak], nextBreak-subBreak, lengthEachSubdivision);  		if (subBreak >= nextBreak) {  			subBreak = -1;  			return TextSegment(startSegment, nextBreak - startSegment); @@ -569,8 +556,8 @@ 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 = new XYPOSITION[lenData]; -		memcpy(positions, other.positions, lenData * sizeof(XYPOSITION)); +		positions.reset(new XYPOSITION[lenData]); +		memcpy(positions.get(), other.positions.get(), lenData * sizeof(XYPOSITION));  	}  } @@ -581,11 +568,11 @@ void PositionCacheEntry::Set(unsigned int styleNumber_, const char *s_,  	len = len_;  	clock = clock_;  	if (s_ && positions_) { -		positions = new XYPOSITION[len + (len / sizeof(XYPOSITION)) + 1]; +		positions.reset(new XYPOSITION[len + (len / sizeof(XYPOSITION)) + 1]);  		for (unsigned int i=0; i<len; i++) {  			positions[i] = positions_[i];  		} -		memcpy(positions + len, s_, len); +		memcpy(&positions[len], s_, len);  	}  } @@ -594,8 +581,7 @@ PositionCacheEntry::~PositionCacheEntry() {  }  void PositionCacheEntry::Clear() { -	delete []positions; -	positions = nullptr; +	positions.reset();  	styleNumber = 0;  	len = 0;  	clock = 0; @@ -604,7 +590,7 @@ void PositionCacheEntry::Clear() {  bool PositionCacheEntry::Retrieve(unsigned int styleNumber_, const char *s_,  	unsigned int len_, XYPOSITION *positions_) const {  	if ((styleNumber == styleNumber_) && (len == len_) && -		(memcmp(positions + len, s_, len)== 0)) { +		(memcmp(&positions[len], s_, len)== 0)) {  		for (unsigned int i=0; i<len; i++) {  			positions_[i] = positions[i];  		} diff --git a/src/PositionCache.h b/src/PositionCache.h index e7008a456..402d657b8 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -47,7 +47,7 @@ enum PointEnd {  class LineLayout {  private:  	friend class LineLayoutCache; -	int *lineStarts; +	std::unique_ptr<int []>lineStarts;  	int lenLineStarts;  	/// Drawing is only performed for @a maxLineLength characters on each line.  	Sci::Line lineNumber; @@ -63,9 +63,9 @@ public:  	bool highlightColumn;  	bool containsCaret;  	int edgeColumn; -	char *chars; -	unsigned char *styles; -	XYPOSITION *positions; +	std::unique_ptr<char[]> chars; +	std::unique_ptr<unsigned char[]> styles; +	std::unique_ptr<XYPOSITION[]> positions;  	char bracePreviousStyles[2];  	// Hotspot support @@ -102,7 +102,7 @@ public:   */  class LineLayoutCache {  	int level; -	std::vector<LineLayout *>cache; +	std::vector<std::unique_ptr<LineLayout>>cache;  	bool allInvalidated;  	int styleClock;  	int useCount; @@ -133,7 +133,7 @@ class PositionCacheEntry {  	unsigned int styleNumber:8;  	unsigned int len:8;  	unsigned int clock:16; -	XYPOSITION *positions; +	std::unique_ptr<XYPOSITION []> positions;  public:  	PositionCacheEntry();  	// Copy constructor not currently used, but needed for being element in std::vector. diff --git a/src/RunStyles.cxx b/src/RunStyles.cxx index 3e611bc92..38a6ba799 100644 --- a/src/RunStyles.cxx +++ b/src/RunStyles.cxx @@ -71,16 +71,12 @@ void RunStyles::RemoveRunIfSameAsPrevious(int run) {  }  RunStyles::RunStyles() { -	starts = new Partitioning(8); -	styles = new SplitVector<int>(); +	starts.reset(new Partitioning(8)); +	styles.reset(new SplitVector<int>());  	styles->InsertValue(0, 2, 0);  }  RunStyles::~RunStyles() { -	delete starts; -	starts = NULL; -	delete styles; -	styles = NULL;  }  int RunStyles::Length() const { @@ -201,12 +197,8 @@ void RunStyles::InsertSpace(int position, int insertLength) {  }  void RunStyles::DeleteAll() { -	delete starts; -	starts = NULL; -	delete styles; -	styles = NULL; -	starts = new Partitioning(8); -	styles = new SplitVector<int>(); +	starts.reset(new Partitioning(8)); +	styles.reset(new SplitVector<int>());  	styles->InsertValue(0, 2, 0);  } diff --git a/src/RunStyles.h b/src/RunStyles.h index bc5213c5a..1c8ef301d 100644 --- a/src/RunStyles.h +++ b/src/RunStyles.h @@ -16,8 +16,8 @@ namespace Scintilla {  class RunStyles {  private: -	Partitioning *starts; -	SplitVector<int> *styles; +	std::unique_ptr<Partitioning> starts; +	std::unique_ptr<SplitVector<int>> styles;  	int RunFromPosition(int position) const;  	int SplitRun(int position);  	void RemoveRun(int run); diff --git a/src/SparseVector.h b/src/SparseVector.h index 250ce97ac..39324bdc1 100644 --- a/src/SparseVector.h +++ b/src/SparseVector.h @@ -17,8 +17,8 @@ namespace Scintilla {  template <typename T>  class SparseVector {  private: -	Partitioning *starts; -	SplitVector<T> *values; +	std::unique_ptr<Partitioning> starts; +	std::unique_ptr<SplitVector<T>> values;  	// Deleted so SparseVector objects can not be copied.  	SparseVector(const SparseVector &) = delete;  	void operator=(const SparseVector &) = delete; @@ -55,19 +55,17 @@ private:  	}  public:  	SparseVector() { -		starts = new Partitioning(8); -		values = new SplitVector<T>(); +		starts.reset(new Partitioning(8)); +		values.reset(new SplitVector<T>());  		values->InsertValue(0, 2, T());  	}  	~SparseVector() { -		delete starts; -		starts = NULL; +		starts.reset();  		// starts dead here but not used by ClearValue.  		for (int part = 0; part < values->Length(); part++) {  			ClearValue(part);  		} -		delete values; -		values = NULL; +		values.reset();  	}  	int Length() const {  		return starts->PositionFromPartition(starts->Partitions()); | 
