Conversation
|
@llvm/pr-subscribers-llvm-adt Author: Franklin (FLZ101) ChangesFull diff: https://github.com/llvm/llvm-project/pull/113048.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index ac40ec4a6b2404..69a08fd079043a 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -198,7 +198,10 @@ namespace llvm {
}
/// slice(n) - Chop off the first N elements of the array.
- ArrayRef<T> slice(size_t N) const { return slice(N, size() - N); }
+ ArrayRef<T> slice(size_t N) const {
+ assert(N <= size() && "Invalid specifier");
+ return slice(N, size() - N);
+ }
/// Drop the first \p N elements of the array.
ArrayRef<T> drop_front(size_t N = 1) const {
|
kuhar
left a comment
There was a problem hiding this comment.
Could you update the PR description and explain what the issue is?
llvm/include/llvm/ADT/ArrayRef.h
Outdated
| assert(N <= size() && "Invalid specifier"); | ||
| return slice(N, size() - N); |
There was a problem hiding this comment.
Instead, we could call into drop_front which does the same thing. Or make drop_front call slice.
There was a problem hiding this comment.
I think drop_front is more idiomatic and we could probably mark the single-argument slice as deprecated and eventually remove it. Although that's all out of scope for this PR. cc: @kazutakahirata
There was a problem hiding this comment.
I've implemented slice(N) with drop_front(N).
|
kuhar
left a comment
There was a problem hiding this comment.
Looks good but please add the explanation from the comment to the commit description when merging.
Current implementation of `slice(N)` is buggy, since `slice(N, size() - N)` will never fail the assertion `assert(N+M <= size() && "Invalid specifier")` above, even `N > size()`.
Done. |
|
@kuhar Could you merge this PR? |
No description provided.