Skip to content

Commit ffa3813

Browse files
committed
feedback
Signed-off-by: Byoungro So <[email protected]>
1 parent 0a4c4fc commit ffa3813

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

sycl/source/detail/device_filter.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,58 +41,52 @@ std::vector<std::string> tokenize(const std::string &Filter,
4141
}
4242

4343
device_filter::device_filter(const std::string &FilterString) {
44-
std::string SubString;
44+
std::vector<std::string> Tokens = tokenize(FilterString, ":");
45+
size_t I = 0;
4546

4647
auto FindElement = [&](auto Element) {
47-
size_t Found = SubString.find(Element.first);
48+
size_t Found = Tokens[I].find(Element.first);
4849
if (Found == std::string::npos)
4950
return false;
5051
return true;
5152
};
5253

5354
// Handle the optional 1st field of the filter, backend
5455
// Check if the first entry matches with a known backend type
55-
std::vector<std::string> Tokens = tokenize(FilterString, ":");
56-
size_t I = 0;
57-
SubString = Tokens[i];
5856
auto It =
59-
std::find_if(std::begin(SyclBeMap), std::end(SyclBeMap), findElement);
57+
std::find_if(std::begin(SyclBeMap), std::end(SyclBeMap), FindElement);
6058
// If no match is found, set the backend type backend::all
6159
// which actually means 'any backend' will be a match.
6260
if (It == SyclBeMap.end())
6361
Backend = backend::all;
6462
else {
6563
Backend = It->second;
66-
i++;
67-
if (i < Tokens.size())
68-
SubString = Tokens[i];
64+
I++;
6965
}
7066

7167
// Handle the optional 2nd field of the filter - device type.
7268
// Check if the 2nd entry matches with any known device type.
73-
if (i >= Tokens.size()) {
69+
if (I >= Tokens.size()) {
7470
DeviceType = info::device_type::all;
7571
} else {
7672
auto Iter = std::find_if(std::begin(SyclDeviceTypeMap),
77-
std::end(SyclDeviceTypeMap), findElement);
73+
std::end(SyclDeviceTypeMap), FindElement);
7874
// If no match is found, set device_type 'all',
7975
// which actually means 'any device_type' will be a match.
8076
if (Iter == SyclDeviceTypeMap.end())
8177
DeviceType = info::device_type::all;
8278
else {
8379
DeviceType = Iter->second;
84-
i++;
85-
if (i < Tokens.size())
86-
SubString = Tokens[i];
80+
I++;
8781
}
8882
}
8983

9084
// Handle the optional 3rd field of the filter, device number
9185
// Try to convert the remaining string to an integer.
9286
// If succeessful, the converted integer is the desired device num.
93-
if (i < Tokens.size()) {
87+
if (I < Tokens.size()) {
9488
try {
95-
DeviceNum = stoi(SubString);
89+
DeviceNum = stoi(Tokens[I]);
9690
HasDeviceNum = true;
9791
} catch (...) {
9892
std::string Message =

0 commit comments

Comments
 (0)