Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using optimized funcs std::find, strchr with char param, constexpr calc len out-of-loop #791

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions shared/offline_compiler/source/decoder/binary_decoder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2024 Intel Corporation
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -237,7 +237,7 @@ void BinaryDecoder::parseTokens() {
break;
} else if (patchList[i].find("PATCH_TOKEN") == std::string::npos) {
continue;
} else if (patchList[i].find("@") == std::string::npos) {
} else if (patchList[i].find('@') == std::string::npos) {
continue;
}

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

nameStartPos = patchList[i].find("@");
nameStartPos = patchList[i].find('@');
nameEndPos = patchList[i].find('@', nameStartPos + 1);
if (nameEndPos == std::string::npos) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions shared/offline_compiler/source/multi_command.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 Intel Corporation
* Copyright (C) 2019-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -189,7 +189,7 @@ int MultiCommand::splitLineInSeparateArgs(std::vector<std::string> &qargs, const
continue;
} else {
start = i;
end = commandsLine.find(" ", start);
end = commandsLine.find(' ', start);
end = (end == std::string::npos) ? commandsLine.length() : end;
}
if (end == std::string::npos) {
Expand Down
4 changes: 2 additions & 2 deletions shared/offline_compiler/source/ocloc_fatbinary.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -306,7 +306,7 @@ int buildFatBinaryForTarget(int retVal, const std::vector<std::string> &argsCopy
}

std::string entryName("");
if (product.find(".") != std::string::npos) {
if (product.find('.') != std::string::npos) {
entryName = product;
} else {
auto productConfig = argHelper->productConfigHelper->getProductConfigFromDeviceName(product);
Expand Down
10 changes: 5 additions & 5 deletions shared/offline_compiler/source/offline_compiler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2024 Intel Corporation
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -247,7 +247,7 @@ std::string formatNameVersionString(std::vector<NameVersionPair> extensions, boo
for (const auto &ext : extensions) {
formatedExtensions.push_back({});
auto it = formatedExtensions.rbegin();
bool needsQuoutes = (nullptr != strstr(ext.name, " "));
bool needsQuoutes = (nullptr != strchr(ext.name, ' '));
it->reserve(strnlen_s(ext.name, sizeof(ext.name)) + (needsQuoutes ? 2 : 0) + (needVersions ? 16 : 0));
if (needsQuoutes) {
it->append("\"");
Expand Down Expand Up @@ -888,7 +888,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &

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

std::string OfflineCompiler::getFileNameTrunk(std::string &filePath) {
size_t slashPos = filePath.find_last_of("\\/", filePath.size()) + 1;
size_t extPos = filePath.find_last_of(".", filePath.size());
size_t extPos = filePath.find_last_of('.', filePath.size());
if (extPos == std::string::npos) {
extPos = filePath.size();
}
Expand Down Expand Up @@ -1576,7 +1576,7 @@ void OfflineCompiler::writeOutAllFiles() {
if (outputFile.empty()) {
elfOutputFile = generateFilePath(outputDirectory, fileBase, ".bin");
} else {
size_t extPos = fileBase.find_last_of(".", fileBase.size());
size_t extPos = fileBase.find_last_of('.', fileBase.size());
std::string fileExt = ".bin";
if (extPos != std::string::npos) {
auto existingExt = fileBase.substr(extPos, fileBase.size());
Expand Down
4 changes: 2 additions & 2 deletions shared/source/device_binary_format/zebin/zeinfo_decoder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Intel Corporation
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -354,7 +354,7 @@ void populateKernelMiscInfo(KernelDescriptor &dst, KernelMiscArgInfos &kernelMis
dstTypeTraits.typeQualifiers = KernelArgMetadata::parseTypeQualifiers(dstMetadata.typeQualifiers);
dst.payloadMappings.explicitArgs.at(srcMetadata.index).getTraits() = std::move(dstTypeTraits);

dstMetadata.type = dstMetadata.type.substr(0U, dstMetadata.type.find(";"));
dstMetadata.type = dstMetadata.type.substr(0U, dstMetadata.type.find(';'));
dst.explicitArgsExtendedMetadata.at(srcMetadata.index) = std::move(dstMetadata);
}
}
Expand Down
12 changes: 6 additions & 6 deletions shared/source/helpers/product_config_helper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2024 Intel Corporation
* Copyright (C) 2022-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -47,7 +47,7 @@ void ProductConfigHelper::adjustDeviceName(std::string &device) {
device = device.substr(0, findCore);
}

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

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

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

uint32_t ProductConfigHelper::getProductConfigFromVersionValue(const std::string &device) {
auto majorPos = device.find(".");
auto majorPos = device.find('.');
auto major = parseProductConfigFromString(device, 0, majorPos);
if (major == ConfigStatus::MismatchedValue || majorPos == std::string::npos) {
return AOT::UNKNOWN_ISA;
}

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

if (minor == ConfigStatus::MismatchedValue || minorPos == std::string::npos) {
Expand Down
9 changes: 6 additions & 3 deletions shared/source/os_interface/linux/drm_neo.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Copyright (C) 2018-2025 Intel Corporation
*
Expand Down Expand Up @@ -658,16 +659,18 @@ std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironme
}

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

auto rdsPos = devicePathView.rfind(renderDeviceSuffix);
if (rdsPos == std::string::npos) {
continue;
}
if (rdsPos < devicePathView.size() - strlen(renderDeviceSuffix)) {
if (rdsPos < devicePathView.size() - renderDevSufSize) {
continue;
}
// at least 'pci-0000:00:00.0' -> 16
Expand Down