Skip to content

Commit 669c8da

Browse files
committed
refactor: using optimized funcs find,strchr with char param, constexpr calc len out-of-loop
1 parent c5d541d commit 669c8da

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

shared/offline_compiler/source/decoder/binary_decoder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void BinaryDecoder::parseTokens() {
237237
break;
238238
} else if (patchList[i].find("PATCH_TOKEN") == std::string::npos) {
239239
continue;
240-
} else if (patchList[i].find("@") == std::string::npos) {
240+
} else if (patchList[i].find('@') == std::string::npos) {
241241
continue;
242242
}
243243

@@ -254,7 +254,7 @@ void BinaryDecoder::parseTokens() {
254254
nameEndPos = patchList[i].find(',', nameStartPos);
255255
patchTokenPtr->name = patchList[i].substr(nameStartPos, nameEndPos - nameStartPos);
256256

257-
nameStartPos = patchList[i].find("@");
257+
nameStartPos = patchList[i].find('@');
258258
nameEndPos = patchList[i].find('@', nameStartPos + 1);
259259
if (nameEndPos == std::string::npos) {
260260
continue;

shared/offline_compiler/source/multi_command.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int MultiCommand::splitLineInSeparateArgs(std::vector<std::string> &qargs, const
189189
continue;
190190
} else {
191191
start = i;
192-
end = commandsLine.find(" ", start);
192+
end = commandsLine.find(' ', start);
193193
end = (end == std::string::npos) ? commandsLine.length() : end;
194194
}
195195
if (end == std::string::npos) {

shared/offline_compiler/source/ocloc_fatbinary.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ int buildFatBinaryForTarget(int retVal, const std::vector<std::string> &argsCopy
306306
}
307307

308308
std::string entryName("");
309-
if (product.find(".") != std::string::npos) {
309+
if (product.find('.') != std::string::npos) {
310310
entryName = product;
311311
} else {
312312
auto productConfig = argHelper->productConfigHelper->getProductConfigFromDeviceName(product);

shared/offline_compiler/source/offline_compiler.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ std::string formatNameVersionString(std::vector<NameVersionPair> extensions, boo
247247
for (const auto &ext : extensions) {
248248
formatedExtensions.push_back({});
249249
auto it = formatedExtensions.rbegin();
250-
bool needsQuoutes = (nullptr != strstr(ext.name, " "));
250+
bool needsQuoutes = (nullptr != strchr(ext.name, ' '));
251251
it->reserve(strnlen_s(ext.name, sizeof(ext.name)) + (needsQuoutes ? 2 : 0) + (needVersions ? 16 : 0));
252252
if (needsQuoutes) {
253253
it->append("\"");
@@ -888,7 +888,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
888888

889889
if (options.empty()) {
890890
// try to read options from file if not provided by commandline
891-
size_t extStart = inputFile.find_last_of(".");
891+
size_t extStart = inputFile.find_last_of('.');
892892
if (extStart != std::string::npos) {
893893
std::string oclocOptionsFileName = inputFile.substr(0, extStart);
894894
oclocOptionsFileName.append("_ocloc_options.txt");
@@ -1236,7 +1236,7 @@ std::string OfflineCompiler::parseBinAsCharArray(uint8_t *binary, size_t size, s
12361236

12371237
std::string OfflineCompiler::getFileNameTrunk(std::string &filePath) {
12381238
size_t slashPos = filePath.find_last_of("\\/", filePath.size()) + 1;
1239-
size_t extPos = filePath.find_last_of(".", filePath.size());
1239+
size_t extPos = filePath.find_last_of('.', filePath.size());
12401240
if (extPos == std::string::npos) {
12411241
extPos = filePath.size();
12421242
}
@@ -1576,7 +1576,7 @@ void OfflineCompiler::writeOutAllFiles() {
15761576
if (outputFile.empty()) {
15771577
elfOutputFile = generateFilePath(outputDirectory, fileBase, ".bin");
15781578
} else {
1579-
size_t extPos = fileBase.find_last_of(".", fileBase.size());
1579+
size_t extPos = fileBase.find_last_of('.', fileBase.size());
15801580
std::string fileExt = ".bin";
15811581
if (extPos != std::string::npos) {
15821582
auto existingExt = fileBase.substr(extPos, fileBase.size());

shared/source/device_binary_format/zebin/zeinfo_decoder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void populateKernelMiscInfo(KernelDescriptor &dst, KernelMiscArgInfos &kernelMis
354354
dstTypeTraits.typeQualifiers = KernelArgMetadata::parseTypeQualifiers(dstMetadata.typeQualifiers);
355355
dst.payloadMappings.explicitArgs.at(srcMetadata.index).getTraits() = std::move(dstTypeTraits);
356356

357-
dstMetadata.type = dstMetadata.type.substr(0U, dstMetadata.type.find(";"));
357+
dstMetadata.type = dstMetadata.type.substr(0U, dstMetadata.type.find(';'));
358358
dst.explicitArgsExtendedMetadata.at(srcMetadata.index) = std::move(dstMetadata);
359359
}
360360
}

shared/source/helpers/product_config_helper.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void ProductConfigHelper::adjustDeviceName(std::string &device) {
4747
device = device.substr(0, findCore);
4848
}
4949

50-
auto findUnderscore = device.find("_");
50+
auto findUnderscore = device.find('_');
5151
if (findUnderscore != std::string::npos) {
5252
device.erase(std::remove(device.begin(), device.end(), '_'), device.end());
5353
}
@@ -146,7 +146,7 @@ bool ProductConfigHelper::isSupportedProductConfig(uint32_t config) const {
146146

147147
AOT::PRODUCT_CONFIG ProductConfigHelper::getProductConfigFromDeviceName(const std::string &device) const {
148148
uint32_t config = AOT::UNKNOWN_ISA;
149-
if (device.find(".") != std::string::npos) {
149+
if (device.find('.') != std::string::npos) {
150150
config = getProductConfigFromVersionValue(device);
151151
} else if (std::all_of(device.begin(), device.end(), (::isdigit))) {
152152
config = static_cast<uint32_t>(std::stoul(device));
@@ -212,7 +212,7 @@ std::vector<NEO::ConstStringRef> ProductConfigHelper::getAllProductAcronyms() {
212212

213213
PRODUCT_FAMILY ProductConfigHelper::getProductFamilyFromDeviceName(const std::string &device) const {
214214
std::vector<DeviceAotInfo>::const_iterator it;
215-
if (device.find(".") != std::string::npos) {
215+
if (device.find('.') != std::string::npos) {
216216
it = std::find_if(deviceAotInfo.begin(), deviceAotInfo.end(), findProductConfig(getProductConfigFromVersionValue(device)));
217217
} else {
218218
it = std::find_if(deviceAotInfo.begin(), deviceAotInfo.end(), findAcronym(device));
@@ -271,13 +271,13 @@ int ProductConfigHelper::parseProductConfigFromString(const std::string &device,
271271
}
272272

273273
uint32_t ProductConfigHelper::getProductConfigFromVersionValue(const std::string &device) {
274-
auto majorPos = device.find(".");
274+
auto majorPos = device.find('.');
275275
auto major = parseProductConfigFromString(device, 0, majorPos);
276276
if (major == ConfigStatus::MismatchedValue || majorPos == std::string::npos) {
277277
return AOT::UNKNOWN_ISA;
278278
}
279279

280-
auto minorPos = device.find(".", ++majorPos);
280+
auto minorPos = device.find('.', ++majorPos);
281281
auto minor = parseProductConfigFromString(device, majorPos, minorPos);
282282

283283
if (minor == ConfigStatus::MismatchedValue || minorPos == std::string::npos) {

shared/source/os_interface/linux/drm_neo.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,17 @@ std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironme
659659

660660
do {
661661
const char *renderDeviceSuffix = "-render";
662+
constexpr size_t renderDevSufSize = std::char_traits<char>::length(renderDeviceSuffix);
663+
constexpr size_t pciDevDirLen = std::char_traits<char>::length(Os::pciDevicesDirectory);
662664
for (std::vector<std::string>::iterator file = files.begin(); file != files.end(); ++file) {
663665
std::string_view devicePathView(file->c_str(), file->size());
664-
devicePathView = devicePathView.substr(strlen(Os::pciDevicesDirectory));
666+
devicePathView = devicePathView.substr(pciDevDirLen);
665667

666668
auto rdsPos = devicePathView.rfind(renderDeviceSuffix);
667669
if (rdsPos == std::string::npos) {
668670
continue;
669671
}
670-
if (rdsPos < devicePathView.size() - strlen(renderDeviceSuffix)) {
672+
if (rdsPos < devicePathView.size() - renderDevSufSize) {
671673
continue;
672674
}
673675
// at least 'pci-0000:00:00.0' -> 16

0 commit comments

Comments
 (0)