We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Learn more about funding links in repositories.
Report abuse
1 parent 2e59d49 commit c74c0bdCopy full SHA for c74c0bd
src/slice.cr
@@ -212,13 +212,17 @@ struct Slice(T)
212
def reverse!
213
check_writable
214
215
- i = 0
216
- j = size - 1
217
- while i < j
218
- @pointer.swap i, j
219
- i += 1
220
- j -= 1
+ return self if size <= 1
+
+ p = @pointer
+ q = @pointer + size - 1
+ while p < q
221
+ p.value, q.value = q.value, p.value
222
+ p += 1
223
+ q -= 1
224
end
225
226
self
227
228
0 commit comments