[llvm] [ADT] Fix ArrayRef<T>::slice (PR #113048)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 20 08:38:35 PDT 2024
https://github.com/FLZ101 updated https://github.com/llvm/llvm-project/pull/113048
>From 9cedd62b4863fff9b9f961da48b565f841633cea Mon Sep 17 00:00:00 2001
From: fengleizZZ <zhangfenglei at huawei.com>
Date: Sat, 19 Oct 2024 22:55:00 +0800
Subject: [PATCH 1/2] [ADT] Fix ArrayRef<T>::slice
---
llvm/include/llvm/ADT/ArrayRef.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
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 {
>From 251d2d80e96f936b1976c6c01dc1c5d5a209cbba Mon Sep 17 00:00:00 2001
From: fengleizZZ <zhangfenglei at huawei.com>
Date: Sun, 20 Oct 2024 23:36:57 +0800
Subject: [PATCH 2/2] [ADT] Fix ArrayRef<T>::slice
implement slice(N) with drop_front(N)
---
llvm/include/llvm/ADT/ArrayRef.h | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index 69a08fd079043a..d9897320ce091a 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -198,10 +198,7 @@ namespace llvm {
}
/// slice(n) - Chop off the first N elements of the array.
- ArrayRef<T> slice(size_t N) const {
- assert(N <= size() && "Invalid specifier");
- return slice(N, size() - N);
- }
+ ArrayRef<T> slice(size_t N) const { return drop_front(N); }
/// Drop the first \p N elements of the array.
ArrayRef<T> drop_front(size_t N = 1) const {
More information about the llvm-commits
mailing list