diff options
| -rw-r--r-- | src/CellBuffer.h | 2 | ||||
| -rw-r--r-- | src/ContractionState.cxx | 2 | ||||
| -rw-r--r-- | src/ContractionState.h | 2 | ||||
| -rw-r--r-- | src/Partitioning.h | 56 | ||||
| -rw-r--r-- | src/RunStyles.cxx | 4 | ||||
| -rw-r--r-- | src/RunStyles.h | 2 | ||||
| -rw-r--r-- | src/SparseVector.h | 4 | ||||
| -rw-r--r-- | test/unit/testPartitioning.cxx | 4 | 
8 files changed, 39 insertions, 37 deletions
| diff --git a/src/CellBuffer.h b/src/CellBuffer.h index edc587dff..a12dc207f 100644 --- a/src/CellBuffer.h +++ b/src/CellBuffer.h @@ -24,7 +24,7 @@ public:   */  class LineVector { -	Partitioning starts; +	Partitioning<int> starts;  	PerLine *perLine;  public: diff --git a/src/ContractionState.cxx b/src/ContractionState.cxx index 3c76d40d1..a9db134bc 100644 --- a/src/ContractionState.cxx +++ b/src/ContractionState.cxx @@ -39,7 +39,7 @@ void ContractionState::EnsureData() {  		expanded.reset(new RunStyles());  		heights.reset(new RunStyles());  		foldDisplayTexts.reset(new SparseVector<UniqueString>()); -		displayLines.reset(new Partitioning(4)); +		displayLines.reset(new Partitioning<int>(4));  		InsertLines(0, linesInDocument);  	}  } diff --git a/src/ContractionState.h b/src/ContractionState.h index 517bf6258..44a531ca5 100644 --- a/src/ContractionState.h +++ b/src/ContractionState.h @@ -21,7 +21,7 @@ class ContractionState {  	std::unique_ptr<RunStyles> expanded;  	std::unique_ptr<RunStyles> heights;  	std::unique_ptr<SparseVector<UniqueString>> foldDisplayTexts; -	std::unique_ptr<Partitioning> displayLines; +	std::unique_ptr<Partitioning<int>> displayLines;  	Sci::Line linesInDocument;  	void EnsureData(); diff --git a/src/Partitioning.h b/src/Partitioning.h index 85e00b328..112a543ca 100644 --- a/src/Partitioning.h +++ b/src/Partitioning.h @@ -14,32 +14,33 @@ namespace Scintilla {  /// in a range.  /// Used by the Partitioning class. -class SplitVectorWithRangeAdd : public SplitVector<int> { +template <typename T> +class SplitVectorWithRangeAdd : public SplitVector<T> {  public:  	explicit SplitVectorWithRangeAdd(ptrdiff_t growSize_) { -		SetGrowSize(growSize_); -		ReAllocate(growSize_); +		this->SetGrowSize(growSize_); +		this->ReAllocate(growSize_);  	}  	// Deleted so SplitVectorWithRangeAdd objects can not be copied.  	SplitVectorWithRangeAdd(const SplitVectorWithRangeAdd &) = delete;  	void operator=(const SplitVectorWithRangeAdd &) = delete;  	~SplitVectorWithRangeAdd() {  	} -	void RangeAddDelta(ptrdiff_t start, ptrdiff_t end, int delta) { +	void RangeAddDelta(ptrdiff_t start, ptrdiff_t end, T delta) {  		// end is 1 past end, so end-start is number of elements to change  		ptrdiff_t i = 0;  		const ptrdiff_t rangeLength = end - start;  		ptrdiff_t range1Length = rangeLength; -		const ptrdiff_t part1Left = part1Length - start; +		const ptrdiff_t part1Left = this->part1Length - start;  		if (range1Length > part1Left)  			range1Length = part1Left;  		while (i < range1Length) { -			body[start++] += delta; +			this->body[start++] += delta;  			i++;  		} -		start += gapLength; +		start += this->gapLength;  		while (i < rangeLength) { -			body[start++] += delta; +			this->body[start++] += delta;  			i++;  		}  	} @@ -52,16 +53,17 @@ public:  /// When needed, positions after the interval are considered part of the last partition  /// but the end of the last partition can be found with PositionFromPartition(last+1). +template <typename T>  class Partitioning {  private:  	// To avoid calculating all the partition positions whenever any text is inserted  	// there may be a step somewhere in the list. -	int stepPartition; -	int stepLength; -	std::unique_ptr<SplitVectorWithRangeAdd> body; +	T stepPartition; +	T stepLength; +	std::unique_ptr<SplitVectorWithRangeAdd<T>> body;  	// Move step forward -	void ApplyStep(int partitionUpTo) { +	void ApplyStep(T partitionUpTo) {  		if (stepLength != 0) {  			body->RangeAddDelta(stepPartition+1, partitionUpTo + 1, stepLength);  		} @@ -73,7 +75,7 @@ private:  	}  	// Move step backward -	void BackStep(int partitionDownTo) { +	void BackStep(T partitionDownTo) {  		if (stepLength != 0) {  			body->RangeAddDelta(partitionDownTo+1, stepPartition+1, -stepLength);  		} @@ -81,7 +83,7 @@ private:  	}  	void Allocate(ptrdiff_t growSize) { -		body.reset(new SplitVectorWithRangeAdd(growSize)); +		body.reset(new SplitVectorWithRangeAdd<T>(growSize));  		stepPartition = 0;  		stepLength = 0;  		body->Insert(0, 0);	// This value stays 0 for ever @@ -100,11 +102,11 @@ public:  	~Partitioning() {  	} -	int Partitions() const { -		return static_cast<int>(body->Length()-1); +	T Partitions() const { +		return static_cast<T>(body->Length())-1;  	} -	void InsertPartition(int partition, int pos) { +	void InsertPartition(T partition, T pos) {  		if (stepPartition < partition) {  			ApplyStep(partition);  		} @@ -112,7 +114,7 @@ public:  		stepPartition++;  	} -	void SetPartitionStartPosition(int partition, int pos) { +	void SetPartitionStartPosition(T partition, T pos) {  		ApplyStep(partition+1);  		if ((partition < 0) || (partition > body->Length())) {  			return; @@ -120,7 +122,7 @@ public:  		body->SetValueAt(partition, pos);  	} -	void InsertText(int partitionInsert, int delta) { +	void InsertText(T partitionInsert, T delta) {  		// Point all the partitions after the insertion point further along in the buffer  		if (stepLength != 0) {  			if (partitionInsert >= stepPartition) { @@ -142,7 +144,7 @@ public:  		}  	} -	void RemovePartition(int partition) { +	void RemovePartition(T partition) {  		if (partition > stepPartition) {  			ApplyStep(partition);  			stepPartition--; @@ -152,29 +154,29 @@ public:  		body->Delete(partition);  	} -	int PositionFromPartition(int partition) const { +	T PositionFromPartition(T partition) const {  		PLATFORM_ASSERT(partition >= 0);  		PLATFORM_ASSERT(partition < body->Length());  		if ((partition < 0) || (partition >= body->Length())) {  			return 0;  		} -		int pos = body->ValueAt(partition); +		T pos = body->ValueAt(partition);  		if (partition > stepPartition)  			pos += stepLength;  		return pos;  	}  	/// Return value in range [0 .. Partitions() - 1] even for arguments outside interval -	int PartitionFromPosition(int pos) const { +	T PartitionFromPosition(T pos) const {  		if (body->Length() <= 1)  			return 0;  		if (pos >= (PositionFromPartition(Partitions())))  			return Partitions() - 1; -		int lower = 0; -		int upper = Partitions(); +		T lower = 0; +		T upper = Partitions();  		do { -			const int middle = (upper + lower + 1) / 2; 	// Round high -			int posMiddle = body->ValueAt(middle); +			const T middle = (upper + lower + 1) / 2; 	// Round high +			T posMiddle = body->ValueAt(middle);  			if (middle > stepPartition)  				posMiddle += stepLength;  			if (pos < posMiddle) { diff --git a/src/RunStyles.cxx b/src/RunStyles.cxx index f6d3d413b..a365df6e9 100644 --- a/src/RunStyles.cxx +++ b/src/RunStyles.cxx @@ -70,7 +70,7 @@ void RunStyles::RemoveRunIfSameAsPrevious(int run) {  }  RunStyles::RunStyles() { -	starts.reset(new Partitioning(8)); +	starts.reset(new Partitioning<int>(8));  	styles.reset(new SplitVector<int>());  	styles->InsertValue(0, 2, 0);  } @@ -196,7 +196,7 @@ void RunStyles::InsertSpace(int position, int insertLength) {  }  void RunStyles::DeleteAll() { -	starts.reset(new Partitioning(8)); +	starts.reset(new Partitioning<int>(8));  	styles.reset(new SplitVector<int>());  	styles->InsertValue(0, 2, 0);  } diff --git a/src/RunStyles.h b/src/RunStyles.h index 8997d924f..84221d512 100644 --- a/src/RunStyles.h +++ b/src/RunStyles.h @@ -14,7 +14,7 @@ namespace Scintilla {  class RunStyles {  private: -	std::unique_ptr<Partitioning> starts; +	std::unique_ptr<Partitioning<int>> starts;  	std::unique_ptr<SplitVector<int>> styles;  	int RunFromPosition(int position) const;  	int SplitRun(int position); diff --git a/src/SparseVector.h b/src/SparseVector.h index f42194f26..0f9f4ad1c 100644 --- a/src/SparseVector.h +++ b/src/SparseVector.h @@ -15,7 +15,7 @@ namespace Scintilla {  template <typename T>  class SparseVector {  private: -	std::unique_ptr<Partitioning> starts; +	std::unique_ptr<Partitioning<int>> starts;  	std::unique_ptr<SplitVector<T>> values;  	T empty;  	// Deleted so SparseVector objects can not be copied. @@ -26,7 +26,7 @@ private:  	}  public:  	SparseVector() : empty() { -		starts.reset(new Partitioning(8)); +		starts.reset(new Partitioning<int>(8));  		values.reset(new SplitVector<T>());  		values->InsertEmpty(0, 2);  	} diff --git a/test/unit/testPartitioning.cxx b/test/unit/testPartitioning.cxx index ed2957289..68471979b 100644 --- a/test/unit/testPartitioning.cxx +++ b/test/unit/testPartitioning.cxx @@ -26,7 +26,7 @@ static const int testArray[lengthTestArray] = {3, 4, 5, 6, 7, 8, 9, 10};  TEST_CASE("SplitVectorWithRangeAdd") { -	SplitVectorWithRangeAdd svwra(growSize); +	SplitVectorWithRangeAdd<int> svwra(growSize);  	SECTION("IsEmptyInitially") {  		REQUIRE(0 == svwra.Length()); @@ -49,7 +49,7 @@ TEST_CASE("SplitVectorWithRangeAdd") {  TEST_CASE("Partitioning") { -	Partitioning part(growSize); +	Partitioning<int> part(growSize);  	SECTION("IsEmptyInitially") {  		REQUIRE(1 == part.Partitions()); | 
