diff options
| author | Neil <nyamatongwe@gmail.com> | 2020-04-08 14:19:22 +1000 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2020-04-08 14:19:22 +1000 | 
| commit | 5ec92254c8c55fff77723eaef6afd437ab88d103 (patch) | |
| tree | 176c6dbc8da0819d711e360ae2fbb65865a71771 /src | |
| parent | b8369870e15d4b061ec5d67d0cfbfe04d3a6459f (diff) | |
| download | scintilla-mirror-5ec92254c8c55fff77723eaef6afd437ab88d103.tar.gz | |
Simplify PerLine, remove casts, use noexcept, const, & constexpr where possible.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Document.cxx | 16 | ||||
| -rw-r--r-- | src/Document.h | 16 | ||||
| -rw-r--r-- | src/PerLine.cxx | 52 | ||||
| -rw-r--r-- | src/PerLine.h | 32 | 
4 files changed, 56 insertions, 60 deletions
| diff --git a/src/Document.cxx b/src/Document.cxx index 263e83d7a..2382e1c21 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -311,7 +311,7 @@ int Document::GetMark(Sci::Line line) const noexcept {  	return Markers()->MarkValue(line);  } -Sci::Line Document::MarkerNext(Sci::Line lineStart, int mask) const { +Sci::Line Document::MarkerNext(Sci::Line lineStart, int mask) const noexcept {  	return Markers()->MarkerNext(lineStart, mask);  } @@ -365,15 +365,15 @@ void Document::DeleteAllMarks(int markerNum) {  	}  } -Sci::Line Document::LineFromHandle(int markerHandle) const { +Sci::Line Document::LineFromHandle(int markerHandle) const noexcept {  	return Markers()->LineFromHandle(markerHandle);  } -int Document::MarkerNumberFromLine(Sci::Line line, int which) const { +int Document::MarkerNumberFromLine(Sci::Line line, int which) const noexcept {  	return Markers()->NumberFromLine(line, which);  } -int Document::MarkerHandleFromLine(Sci::Line line, int which) const { +int Document::MarkerHandleFromLine(Sci::Line line, int which) const noexcept {  	return Markers()->HandleFromLine(line, which);  } @@ -2292,7 +2292,7 @@ int SCI_METHOD Document::GetLineState(Sci_Position line) const {  	return States()->GetLineState(line);  } -Sci::Line Document::GetMaxLineState() const { +Sci::Line Document::GetMaxLineState() const noexcept {  	return States()->GetMaxLineState();  } @@ -2302,7 +2302,7 @@ void SCI_METHOD Document::ChangeLexerState(Sci_Position start, Sci_Position end)  	NotifyModified(mh);  } -StyledText Document::MarginStyledText(Sci::Line line) const { +StyledText Document::MarginStyledText(Sci::Line line) const noexcept {  	const LineAnnotation *pla = Margins();  	return StyledText(pla->Length(line), pla->Text(line),  		pla->MultipleStyles(line), pla->Style(line), pla->Styles(line)); @@ -2335,7 +2335,7 @@ void Document::MarginClearAll() {  	Margins()->ClearAll();  } -StyledText Document::AnnotationStyledText(Sci::Line line) const { +StyledText Document::AnnotationStyledText(Sci::Line line) const noexcept {  	const LineAnnotation *pla = Annotations();  	return StyledText(pla->Length(line), pla->Text(line),  		pla->MultipleStyles(line), pla->Style(line), pla->Styles(line)); @@ -2366,7 +2366,7 @@ void Document::AnnotationSetStyles(Sci::Line line, const unsigned char *styles)  	}  } -int Document::AnnotationLines(Sci::Line line) const { +int Document::AnnotationLines(Sci::Line line) const noexcept {  	return Annotations()->Lines(line);  } diff --git a/src/Document.h b/src/Document.h index 1f03dda1d..a1d9ff7c2 100644 --- a/src/Document.h +++ b/src/Document.h @@ -396,15 +396,15 @@ public:  		cb.GetStyleRange(buffer, position, lengthRetrieve);  	}  	int GetMark(Sci::Line line) const noexcept; -	Sci::Line MarkerNext(Sci::Line lineStart, int mask) const; +	Sci::Line MarkerNext(Sci::Line lineStart, int mask) const noexcept;  	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) const; -	int MarkerNumberFromLine(Sci::Line line, int which) const; -	int MarkerHandleFromLine(Sci::Line line, int which) const; +	Sci::Line LineFromHandle(int markerHandle) const noexcept; +	int MarkerNumberFromLine(Sci::Line line, int which) const noexcept; +	int MarkerHandleFromLine(Sci::Line line, int which) const noexcept;  	Sci_Position SCI_METHOD LineStart(Sci_Position line) const override;  	bool IsLineStartPosition(Sci::Position position) const;  	Sci_Position SCI_METHOD LineEnd(Sci_Position line) const override; @@ -466,20 +466,20 @@ public:  	int SCI_METHOD SetLineState(Sci_Position line, int state) override;  	int SCI_METHOD GetLineState(Sci_Position line) const override; -	Sci::Line GetMaxLineState() const; +	Sci::Line GetMaxLineState() const noexcept;  	void SCI_METHOD ChangeLexerState(Sci_Position start, Sci_Position end) override; -	StyledText MarginStyledText(Sci::Line line) const; +	StyledText MarginStyledText(Sci::Line line) const noexcept;  	void MarginSetStyle(Sci::Line line, int style);  	void MarginSetStyles(Sci::Line line, const unsigned char *styles);  	void MarginSetText(Sci::Line line, const char *text);  	void MarginClearAll(); -	StyledText AnnotationStyledText(Sci::Line line) const; +	StyledText AnnotationStyledText(Sci::Line line) const noexcept;  	void AnnotationSetText(Sci::Line line, const char *text);  	void AnnotationSetStyle(Sci::Line line, int style);  	void AnnotationSetStyles(Sci::Line line, const unsigned char *styles); -	int AnnotationLines(Sci::Line line) const; +	int AnnotationLines(Sci::Line line) const noexcept;  	void AnnotationClearAll();  	bool AddWatcher(DocWatcher *watcher, void *userData); diff --git a/src/PerLine.cxx b/src/PerLine.cxx index 31da695ad..aa85faa28 100644 --- a/src/PerLine.cxx +++ b/src/PerLine.cxx @@ -85,7 +85,7 @@ bool MarkerHandleSet::RemoveNumber(int markerNum, bool all) {  	return performedDeletion;  } -void MarkerHandleSet::CombineWith(MarkerHandleSet *other) { +void MarkerHandleSet::CombineWith(MarkerHandleSet *other) noexcept {  	mhList.splice_after(mhList.before_begin(), other->mhList);  } @@ -112,20 +112,16 @@ void LineMarkers::RemoveLine(Sci::Line line) {  	}  } -Sci::Line LineMarkers::LineFromHandle(int markerHandle) { -	if (markers.Length()) { -		for (Sci::Line line = 0; line < markers.Length(); line++) { -			if (markers[line]) { -				if (markers[line]->Contains(markerHandle)) { -					return line; -				} -			} +Sci::Line LineMarkers::LineFromHandle(int markerHandle) const noexcept { +	for (Sci::Line line = 0; line < markers.Length(); line++) { +		if (markers[line] && markers[line]->Contains(markerHandle)) { +			return line;  		}  	}  	return -1;  } -int LineMarkers::HandleFromLine(Sci::Line line, int which) const { +int LineMarkers::HandleFromLine(Sci::Line line, int which) const noexcept {  	if (markers.Length() && (line >= 0) && (line < markers.Length()) && markers[line]) {  		MarkerHandleNumber const *pnmh = markers[line]->GetMarkerHandleNumber(which);  		return pnmh ? pnmh->handle : -1; @@ -133,7 +129,7 @@ int LineMarkers::HandleFromLine(Sci::Line line, int which) const {  	return -1;  } -int LineMarkers::NumberFromLine(Sci::Line line, int which) const { +int LineMarkers::NumberFromLine(Sci::Line line, int which) const noexcept {  	if (markers.Length() && (line >= 0) && (line < markers.Length()) && markers[line]) {  		MarkerHandleNumber const *pnmh = markers[line]->GetMarkerHandleNumber(which);  		return pnmh ? pnmh->number : -1; @@ -150,17 +146,17 @@ void LineMarkers::MergeMarkers(Sci::Line line) {  	}  } -int LineMarkers::MarkValue(Sci::Line line) noexcept { +int LineMarkers::MarkValue(Sci::Line line) const noexcept {  	if (markers.Length() && (line >= 0) && (line < markers.Length()) && markers[line])  		return markers[line]->MarkValue();  	else  		return 0;  } -Sci::Line LineMarkers::MarkerNext(Sci::Line lineStart, int mask) const { +Sci::Line LineMarkers::MarkerNext(Sci::Line lineStart, int mask) const noexcept {  	if (lineStart < 0)  		lineStart = 0; -	const Sci::Line length = static_cast<Sci::Line>(markers.Length()); +	const Sci::Line length = markers.Length();  	for (Sci::Line iLine = lineStart; iLine < length; iLine++) {  		const MarkerHandleSet *onLine = markers[iLine].get();  		if (onLine && ((onLine->MarkValue() & mask) != 0)) @@ -262,7 +258,7 @@ int LineLevels::SetLevel(Sci::Line line, int level, Sci::Line lines) {  	return prev;  } -int LineLevels::GetLevel(Sci::Line line) const { +int LineLevels::GetLevel(Sci::Line line) const noexcept {  	if (levels.Length() && (line >= 0) && (line < levels.Length())) {  		return levels[line];  	} else { @@ -305,8 +301,8 @@ int LineState::GetLineState(Sci::Line line) {  	return lineStates[line];  } -Sci::Line LineState::GetMaxLineState() const { -	return static_cast<Sci::Line>(lineStates.Length()); +Sci::Line LineState::GetMaxLineState() const noexcept { +	return lineStates.Length();  }  static int NumberLines(const char *text) noexcept { @@ -326,7 +322,7 @@ static int NumberLines(const char *text) noexcept {  // Each allocated LineAnnotation is a char array which starts with an AnnotationHeader  // and then has text and optional styles. -static const int IndividualStyles = 0x100; +static constexpr int IndividualStyles = 0x100;  struct AnnotationHeader {  	short style;	// Style IndividualStyles implies array of styles @@ -355,35 +351,35 @@ void LineAnnotation::RemoveLine(Sci::Line line) {  	}  } -bool LineAnnotation::MultipleStyles(Sci::Line line) const { +bool LineAnnotation::MultipleStyles(Sci::Line line) const noexcept {  	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return reinterpret_cast<AnnotationHeader *>(annotations[line].get())->style == IndividualStyles;  	else  		return false;  } -int LineAnnotation::Style(Sci::Line line) const { +int LineAnnotation::Style(Sci::Line line) const noexcept {  	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return reinterpret_cast<AnnotationHeader *>(annotations[line].get())->style;  	else  		return 0;  } -const char *LineAnnotation::Text(Sci::Line line) const { +const char *LineAnnotation::Text(Sci::Line line) const noexcept {  	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return annotations[line].get()+sizeof(AnnotationHeader);  	else  		return nullptr;  } -const unsigned char *LineAnnotation::Styles(Sci::Line line) const { +const unsigned char *LineAnnotation::Styles(Sci::Line line) const noexcept {  	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line] && MultipleStyles(line))  		return reinterpret_cast<unsigned char *>(annotations[line].get() + sizeof(AnnotationHeader) + Length(line));  	else  		return nullptr;  } -static std::unique_ptr<char[]>AllocateAnnotation(int length, int style) { +static std::unique_ptr<char[]>AllocateAnnotation(size_t length, int style) {  	const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0);  	return std::make_unique<char[]>(len);  } @@ -392,7 +388,7 @@ void LineAnnotation::SetText(Sci::Line line, const char *text) {  	if (text && (line >= 0)) {  		annotations.EnsureLength(line+1);  		const int style = Style(line); -		annotations[line] = AllocateAnnotation(static_cast<int>(strlen(text)), style); +		annotations[line] = AllocateAnnotation(strlen(text), style);  		char *pa = annotations[line].get();  		assert(pa);  		AnnotationHeader *pah = reinterpret_cast<AnnotationHeader *>(pa); @@ -441,14 +437,14 @@ void LineAnnotation::SetStyles(Sci::Line line, const unsigned char *styles) {  	}  } -int LineAnnotation::Length(Sci::Line line) const { +int LineAnnotation::Length(Sci::Line line) const noexcept {  	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return reinterpret_cast<AnnotationHeader *>(annotations[line].get())->length;  	else  		return 0;  } -int LineAnnotation::Lines(Sci::Line line) const { +int LineAnnotation::Lines(Sci::Line line) const noexcept {  	if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])  		return reinterpret_cast<AnnotationHeader *>(annotations[line].get())->lines;  	else @@ -476,7 +472,7 @@ void LineTabstops::RemoveLine(Sci::Line line) {  	}  } -bool LineTabstops::ClearTabstops(Sci::Line line) { +bool LineTabstops::ClearTabstops(Sci::Line line) noexcept {  	if (line < tabstops.Length()) {  		TabstopList *tl = tabstops[line].get();  		if (tl) { @@ -506,7 +502,7 @@ bool LineTabstops::AddTabstop(Sci::Line line, int x) {  	return false;  } -int LineTabstops::GetNextTabstop(Sci::Line line, int x) const { +int LineTabstops::GetNextTabstop(Sci::Line line, int x) const noexcept {  	if (line < tabstops.Length()) {  		TabstopList *tl = tabstops[line].get();  		if (tl) { diff --git a/src/PerLine.h b/src/PerLine.h index 3da02b5e5..b6565fcc1 100644 --- a/src/PerLine.h +++ b/src/PerLine.h @@ -40,7 +40,7 @@ public:  	bool InsertHandle(int handle, int markerNum);  	void RemoveHandle(int handle);  	bool RemoveNumber(int markerNum, bool all); -	void CombineWith(MarkerHandleSet *other); +	void CombineWith(MarkerHandleSet *other) noexcept;  	MarkerHandleNumber const *GetMarkerHandleNumber(int which) const noexcept;  }; @@ -61,15 +61,15 @@ public:  	void InsertLine(Sci::Line line) override;  	void RemoveLine(Sci::Line line) override; -	int MarkValue(Sci::Line line) noexcept; -	Sci::Line MarkerNext(Sci::Line lineStart, int mask) const; +	int MarkValue(Sci::Line line) const noexcept; +	Sci::Line MarkerNext(Sci::Line lineStart, int mask) const noexcept;  	int AddMark(Sci::Line line, int markerNum, Sci::Line lines);  	void MergeMarkers(Sci::Line line);  	bool DeleteMark(Sci::Line line, int markerNum, bool all);  	void DeleteMarkFromHandle(int markerHandle); -	Sci::Line LineFromHandle(int markerHandle); -	int HandleFromLine(Sci::Line line, int which) const; -	int NumberFromLine(Sci::Line line, int which) const; +	Sci::Line LineFromHandle(int markerHandle) const noexcept; +	int HandleFromLine(Sci::Line line, int which) const noexcept; +	int NumberFromLine(Sci::Line line, int which) const noexcept;  };  class LineLevels : public PerLine { @@ -90,7 +90,7 @@ public:  	void ExpandLevels(Sci::Line sizeNew=-1);  	void ClearLevels();  	int SetLevel(Sci::Line line, int level, Sci::Line lines); -	int GetLevel(Sci::Line line) const; +	int GetLevel(Sci::Line line) const noexcept;  };  class LineState : public PerLine { @@ -110,7 +110,7 @@ public:  	int SetLineState(Sci::Line line, int state);  	int GetLineState(Sci::Line line); -	Sci::Line GetMaxLineState() const; +	Sci::Line GetMaxLineState() const noexcept;  };  class LineAnnotation : public PerLine { @@ -128,16 +128,16 @@ public:  	void InsertLine(Sci::Line line) override;  	void RemoveLine(Sci::Line line) override; -	bool MultipleStyles(Sci::Line line) const; -	int Style(Sci::Line line) const; -	const char *Text(Sci::Line line) const; -	const unsigned char *Styles(Sci::Line line) const; +	bool MultipleStyles(Sci::Line line) const noexcept; +	int Style(Sci::Line line) const noexcept; +	const char *Text(Sci::Line line) const noexcept; +	const unsigned char *Styles(Sci::Line line) const noexcept;  	void SetText(Sci::Line line, const char *text);  	void ClearAll();  	void SetStyle(Sci::Line line, int style);  	void SetStyles(Sci::Line line, const unsigned char *styles); -	int Length(Sci::Line line) const; -	int Lines(Sci::Line line) const; +	int Length(Sci::Line line) const noexcept; +	int Lines(Sci::Line line) const noexcept;  };  typedef std::vector<int> TabstopList; @@ -157,9 +157,9 @@ public:  	void InsertLine(Sci::Line line) override;  	void RemoveLine(Sci::Line line) override; -	bool ClearTabstops(Sci::Line line); +	bool ClearTabstops(Sci::Line line) noexcept;  	bool AddTabstop(Sci::Line line, int x); -	int GetNextTabstop(Sci::Line line, int x) const; +	int GetNextTabstop(Sci::Line line, int x) const noexcept;  };  } | 
