Skip to content

Commit 116af80

Browse files
cyyeverpytorchmergebot
authored andcommitted
Use std::string_view (pytorch#145906)
Fixes #ISSUE_NUMBER Pull Request resolved: pytorch#145906 Approved by: https://github.com/albanD
1 parent 933b6d9 commit 116af80

File tree

20 files changed

+29
-28
lines changed

20 files changed

+29
-28
lines changed

aten/src/ATen/Dispatch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <c10/util/Half.h>
77
#include <c10/util/Metaprogramming.h>
88
#include <c10/util/complex.h>
9-
#include <c10/util/string_view.h>
109

1110
#ifdef __CUDACC__
1211
#include <cuda.h> // For CUDA_VERSION

aten/src/ATen/MapAllocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include <c10/core/Allocator.h>
4-
#include <c10/util/string_view.h>
4+
#include <string_view>
55

66
namespace at {
77

aten/src/ATen/PadNd.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#pragma once
2-
#include <c10/util/Exception.h>
3-
#include <c10/util/string_view.h>
42

53
namespace at {
64

aten/src/ATen/core/ATen_pch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <sstream>
5555
#include <stdexcept>
5656
#include <string>
57+
#include <string_view>
5758
#include <tuple>
5859
#include <type_traits>
5960
#include <typeindex>

aten/src/ATen/core/function_schema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#pragma once
22

33
#include <c10/util/StringUtil.h>
4-
#include <c10/util/string_view.h>
54
#include <c10/util/irange.h>
65
#include <ATen/core/jit_type.h>
76
#include <ATen/core/symbol.h>
87
#include <ATen/core/ivalue.h>
98
#include <ATen/core/alias_info.h>
109
#include <ATen/core/operator_name.h>
1110
#include <ATen/core/dispatch/OperatorOptions.h>
11+
#include <string_view>
1212
#include <unordered_map>
1313
#include <utility>
1414

aten/src/ATen/core/op_registration/op_allowlist.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* will fail (and the operator will be included in the binary anyway).
2626
*/
2727

28-
#include <c10/util/string_view.h>
28+
#include <string_view>
2929
#include <c10/core/DispatchKey.h>
3030
#include <c10/macros/Macros.h>
3131

@@ -36,7 +36,7 @@
3636

3737
namespace c10::impl {
3838

39-
constexpr bool allowlist_contains(string_view allowlist, string_view item); // Forward Declare
39+
constexpr bool allowlist_contains(std::string_view allowlist, std::string_view item); // Forward Declare
4040

4141
/**
4242
* In selective build mode returns true/false depending on whether a build
@@ -102,14 +102,14 @@ constexpr bool is_build_feature_available(const char* name) {
102102

103103
// returns true iff allowlist contains item
104104
// allowlist_contains("a;bc;d", "bc") == true
105-
constexpr bool allowlist_contains(string_view allowlist, string_view item) {
105+
constexpr bool allowlist_contains(std::string_view allowlist, std::string_view item) {
106106
//Choose a really big value for next so that if something goes wrong
107107
//this code will blow up in a hopefully detectable way.
108108
size_t next = std::numeric_limits<size_t>::max();
109109
for (size_t cur = 0; cur <= allowlist.size(); cur = next) {
110110
next = allowlist.find(';', cur);
111-
if (next != string_view::npos) {
112-
if (allowlist.substr(cur, next - cur).compare(item) == 0) {
111+
if (next != std::string_view::npos) {
112+
if (allowlist.substr(cur, next - cur) == item) {
113113
return true;
114114
}
115115
next++;
@@ -125,12 +125,12 @@ constexpr bool allowlist_contains(string_view allowlist, string_view item) {
125125

126126
// Returns true iff the given op name is on the allowlist
127127
// and should be registered
128-
constexpr bool op_allowlist_check(string_view op_name [[maybe_unused]]) {
129-
assert(op_name.find("::") != string_view::npos);
128+
constexpr bool op_allowlist_check(std::string_view op_name [[maybe_unused]]) {
129+
assert(op_name.find("::") != std::string_view::npos);
130130
// Use assert() instead of throw() due to a gcc bug. See:
131131
// https://stackoverflow.com/questions/34280729/throw-in-constexpr-function
132132
// https://github.com/fmtlib/fmt/issues/682
133-
assert(op_name.find("(") == string_view::npos);
133+
assert(op_name.find('(') == std::string_view::npos);
134134
#if !defined(TORCH_OPERATOR_WHITELIST)
135135
// If the TORCH_OPERATOR_WHITELIST parameter is not defined,
136136
// all ops are to be registered
@@ -150,21 +150,20 @@ constexpr bool op_allowlist_check(string_view op_name [[maybe_unused]]) {
150150

151151
// Returns true iff the given schema string is on the allowlist
152152
// and should be registered
153-
constexpr bool schema_allowlist_check(string_view schema) {
153+
constexpr bool schema_allowlist_check(std::string_view schema) {
154154
#if defined(TORCH_FORCE_SCHEMA_REGISTRATION)
155155
return true;
156156
#else
157-
return op_allowlist_check(schema.substr(0, schema.find("(")));
157+
return op_allowlist_check(schema.substr(0, schema.find('(')));
158158
#endif
159159
}
160160

161161
// Returns true iff the given custom class name is on the allowlist
162162
// and should be registered
163-
constexpr bool custom_class_allowlist_check(string_view custom_class_name) {
163+
constexpr bool custom_class_allowlist_check(std::string_view custom_class_name [[maybe_unused]]) {
164164
#if !defined(TORCH_CUSTOM_CLASS_ALLOWLIST)
165165
// If the TORCH_CUSTOM_CLASS_ALLOWLIST parameter is not defined,
166166
// all custom classes are to be registered
167-
(void)custom_class_name;
168167
return true;
169168
#else
170169
return allowlist_contains(
@@ -175,8 +174,8 @@ constexpr bool custom_class_allowlist_check(string_view custom_class_name) {
175174

176175
// schema_allowlist_check() implicitly depends on a macro, TORCH_OPERATOR_WHITELIST.
177176
// Add this API to pass arbitrary allowlist.
178-
constexpr bool op_allowlist_contains_name_in_schema(string_view allowlist, string_view schema) {
179-
return allowlist_contains(allowlist, schema.substr(0, schema.find("(")));
177+
constexpr bool op_allowlist_contains_name_in_schema(std::string_view allowlist, std::string_view schema) {
178+
return allowlist_contains(allowlist, schema.substr(0, schema.find('(')));
180179
}
181180

182181
// Returns true iff the given dispatch key is on the allowlist

aten/src/ATen/core/operator_name.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
#include <c10/macros/Macros.h>
44
#include <c10/util/Exception.h>
5-
#include <c10/util/string_view.h>
65

76
#include <cstring>
87
#include <optional>
98
#include <ostream>
109
#include <string>
10+
#include <string_view>
1111
#include <utility>
1212

1313
namespace c10 {

aten/src/ATen/native/BatchLinearAlgebra.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include <optional>
4-
#include <c10/util/string_view.h>
4+
#include <string_view>
55
#include <ATen/Config.h>
66
#include <ATen/native/DispatchStub.h>
77

aten/src/ATen/native/Gelu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include <c10/util/Exception.h>
4-
#include <c10/util/string_view.h>
4+
#include <string_view>
55

66
namespace at::native {
77
// These constants control the approximation behavior of gelu function.

aten/src/ATen/native/nested/NestedTensorTransformerFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include <ATen/NestedTensorImpl.h>
66
#include <ATen/native/nested/NestedTensorUtils.h>
77

8-
#include <c10/util/string_view.h>
98
#include <c10/util/Exception.h>
109
#include <optional>
10+
#include <string_view>
1111

1212
namespace at::native {
1313
namespace {

0 commit comments

Comments
 (0)