Skip to content

Commit 5eb3113

Browse files
author
Petr Sramek
committed
merged
1 parent 90ee11e commit 5eb3113

File tree

2 files changed

+16
-75
lines changed

2 files changed

+16
-75
lines changed

benchmarks/PolylineAlgorithm.Benchmarks/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
namespace PolylineAlgorithm.Benchmarks;
77

8-
using BenchmarkDotNet.Configs;
98
using BenchmarkDotNet.Running;
109

1110
/// <summary>
@@ -21,6 +20,6 @@ static void Main(string[] args) {
2120

2221
BenchmarkSwitcher
2322
.FromAssembly(typeof(Program).Assembly)
24-
.Run(args, new DebugInProcessConfig());
23+
.Run(args,/* new DebugInProcessConfig()*/);
2524
}
2625
}

src/PolylineAlgorithm/Polyline.cs

Lines changed: 15 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -94,87 +94,29 @@ public Polyline Append(ReadOnlyMemory<char> value) {
9494
return this;
9595
}
9696

97-
Memory<char> temp = new char[Length + value.Length];
97+
long position = 0;
98+
var enumerator = Value.GetEnumerator();
99+
var right = new SequenceReader<byte>(other.Value);
98100

99-
Value.CopyTo(temp);
100-
value.CopyTo(temp[Value.Length..]);
101-
101+
while (true) {
102+
if (!enumerator.MoveNext()) {
103+
break;
104+
}
102105

103-
return Polyline.FromMemory(temp);
104-
}
105-
106-
//private PolylineSegment GetSegments(out PolylineSegment initial) {
107-
// initial = new PolylineSegment(Value.First);
108-
109-
// if (Value.IsSingleSegment) {
110-
// return initial;
111-
// }
112-
113-
// PolylineSegment? current = null;
114-
115-
// foreach (var segment in Value) {
116-
// if (current is null) {
117-
// current = initial;
118-
// } else {
119-
// current = current.Append(segment);
120-
// }
121-
// }
122-
123-
// // Current will never be null in case we return from the method early using Value.IsSingleSegment property check
124-
// return current!;
125-
//}
126-
127-
#region Overrides
128-
129-
/// <inheritdoc />
130-
[ExcludeFromCodeCoverage]
131-
public override bool Equals(object? obj) => obj is Polyline polyline && Equals(polyline);
132-
133-
/// <inheritdoc />
134-
[ExcludeFromCodeCoverage]
135-
public override int GetHashCode() => HashCode.Combine(Value);
136-
137-
#endregion
138-
139-
#region IEquatable<Polyline> implementation
106+
if (enumerator.Current.IsEmpty) {
107+
continue;
108+
}
140109

141-
/// <inheritdoc />
142-
public bool Equals(Polyline other) {
143-
if(IsEmpty && other.IsEmpty) {
144-
return true;
145-
}
110+
if (!right.IsNext(enumerator.Current.Span, true)) {
111+
break;
112+
}
146113

147-
if(Length != other.Length) {
148-
return false;
114+
position += enumerator.Current.Length;
149115
}
150116

151-
return Value.Span.SequenceEqual(other.Value.Span);
117+
return position == right.Length;
152118
}
153119

154-
#endregion
155-
156-
#region Equality operators
157-
158-
/// <summary>
159-
/// Indicates whether the values of two specified <see cref="Polyline" /> objects are equal.
160-
/// </summary>
161-
/// <param name="left">The first object to compare.</param>
162-
/// <param name="right">The second object to compare.</param>
163-
/// <returns><see langword="true"/> if <paramref name="left"/> and <paramref name="right"/> are equal; otherwise, <see langword="false"/>.</returns>
164-
[ExcludeFromCodeCoverage]
165-
public static bool operator ==(Polyline left, Polyline right) => left.Equals(right);
166-
167-
/// <summary>
168-
/// Indicates whether the values of two specified <see cref="Polyline" /> objects are not equal.
169-
/// </summary>
170-
/// <param name="left">The first object to compare.</param>
171-
/// <param name="right">The second object to compare.</param>
172-
/// <returns><see langword="true"/> if <paramref name="left"/> and <paramref name="right"/> are not equal; otherwise, <see langword="false"/>.</returns>
173-
[ExcludeFromCodeCoverage]
174-
public static bool operator !=(Polyline left, Polyline right) => !(left == right);
175-
176-
#endregion
177-
178120
#region Factory methods
179121

180122
/// <summary>

0 commit comments

Comments
 (0)