From 90005f5a984d5d58789f82982f01a0aa534f3209 Mon Sep 17 00:00:00 2001 From: Herman Semenov Date: Sat, 4 Jan 2025 21:51:33 +0300 Subject: [PATCH] refactor: remove excess cast to C-string and add const reference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Semenov Herman (Семенов Герман) --- shared/offline_compiler/source/offline_compiler.cpp | 4 ++-- .../compiler_interface/linux/compiler_cache_linux.cpp | 6 +++--- .../execution_environment_drm_or_wddm.cpp | 8 ++++---- shared/source/helpers/linux/path.cpp | 4 ++-- .../source/kernel/kernel_descriptor_from_patchtokens.cpp | 6 +++--- shared/source/os_interface/linux/drm_neo.cpp | 4 ++-- shared/source/os_interface/windows/wddm/wddm.cpp | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/shared/offline_compiler/source/offline_compiler.cpp b/shared/offline_compiler/source/offline_compiler.cpp index 870db00f2f082..3c782ada2d418 100644 --- a/shared/offline_compiler/source/offline_compiler.cpp +++ b/shared/offline_compiler/source/offline_compiler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -936,7 +936,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector & } } - retVal = deviceName.empty() ? OCLOC_SUCCESS : initHardwareInfo(deviceName.c_str()); + retVal = deviceName.empty() ? OCLOC_SUCCESS : initHardwareInfo(deviceName); if (retVal != OCLOC_SUCCESS) { argHelper->printf("Error: Cannot get HW Info for device %s.\n", deviceName.c_str()); return retVal; diff --git a/shared/source/compiler_interface/linux/compiler_cache_linux.cpp b/shared/source/compiler_interface/linux/compiler_cache_linux.cpp index a6721104730c6..6164c6e0d9fce 100644 --- a/shared/source/compiler_interface/linux/compiler_cache_linux.cpp +++ b/shared/source/compiler_interface/linux/compiler_cache_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -63,7 +63,7 @@ bool CompilerCache::evictCache(uint64_t &bytesEvicted) { for (int i = 0; i < filesCount; ++i) { ElementsStruct fileElement = {}; fileElement.path = joinPath(config.cacheDir, files[i]->d_name); - if (NEO::SysCalls::stat(fileElement.path.c_str(), &fileElement.statEl) == 0) { + if (NEO::SysCalls::stat(fileElement.path, &fileElement.statEl) == 0) { cacheFiles.push_back(std::move(fileElement)); } free(files[i]); @@ -177,7 +177,7 @@ void CompilerCache::lockConfigFileAndReadSize(const std::string &configFilePath, if (fileName.find(config.cacheFileExtension) != fileName.npos) { ElementsStruct fileElement = {}; fileElement.path = joinPath(config.cacheDir, files[i]->d_name); - if (NEO::SysCalls::stat(fileElement.path.c_str(), &fileElement.statEl) == 0) { + if (NEO::SysCalls::stat(fileElement.path, &fileElement.statEl) == 0) { cacheFiles.push_back(std::move(fileElement)); } } diff --git a/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp b/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp index 5481a72d23e97..1de4065f49c03 100644 --- a/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp +++ b/shared/source/execution_environment/execution_environment_drm_or_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -42,16 +42,16 @@ void ExecutionEnvironment::configureCcsMode() { return; } - const std::string drmPath = "/sys/class/drm"; + const std::string &drmPath = "/sys/class/drm"; std::string expectedFilePrefix = drmPath + "/card"; - auto files = Directory::getFiles(drmPath.c_str()); + const auto &files = Directory::getFiles(drmPath); for (const auto &file : files) { if (file.find(expectedFilePrefix.c_str()) == std::string::npos) { continue; } std::string gtPath = file + "/gt"; - auto gtFiles = Directory::getFiles(gtPath.c_str()); + const auto >Files = Directory::getFiles(gtPath); expectedFilePrefix = gtPath + "/gt"; for (const auto >File : gtFiles) { if (gtFile.find(expectedFilePrefix.c_str()) == std::string::npos) { diff --git a/shared/source/helpers/linux/path.cpp b/shared/source/helpers/linux/path.cpp index e90f066853c95..84f797088cddb 100644 --- a/shared/source/helpers/linux/path.cpp +++ b/shared/source/helpers/linux/path.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -15,7 +15,7 @@ namespace NEO { bool pathExists(const std::string &path) { struct stat statbuf = {}; - if (NEO::SysCalls::stat(path.c_str(), &statbuf) == -1) { + if (NEO::SysCalls::stat(path, &statbuf) == -1) { return false; } diff --git a/shared/source/kernel/kernel_descriptor_from_patchtokens.cpp b/shared/source/kernel/kernel_descriptor_from_patchtokens.cpp index dd31a860a51d9..7025c7f32f80d 100644 --- a/shared/source/kernel/kernel_descriptor_from_patchtokens.cpp +++ b/shared/source/kernel/kernel_descriptor_from_patchtokens.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -113,7 +113,7 @@ void populateKernelDescriptor(KernelDescriptor &dst, const SPatchDataParameterSt void populateKernelDescriptor(KernelDescriptor &dst, const SPatchKernelAttributesInfo &token) { constexpr ConstStringRef attributeReqdSubGroupSizeBeg = "intel_reqd_sub_group_size("; - std::string attributes = std::string(reinterpret_cast(&token + 1), token.AttributesSize).c_str(); + const auto &attributes = std::string(reinterpret_cast(&token + 1), token.AttributesSize); dst.kernelMetadata.kernelLanguageAttributes = attributes; auto it = attributes.find(attributeReqdSubGroupSizeBeg.begin()); if (it != std::string::npos) { @@ -460,7 +460,7 @@ void populateArgDescriptor(KernelDescriptor &dst, size_t argNum, const PatchToke void populateKernelDescriptor(KernelDescriptor &dst, const PatchTokenBinary::KernelFromPatchtokens &src, uint32_t gpuPointerSizeInBytes) { UNRECOVERABLE_IF(nullptr == src.header); - dst.kernelMetadata.kernelName = std::string(src.name.begin(), src.name.end()).c_str(); + dst.kernelMetadata.kernelName = std::string(src.name.begin(), src.name.end()); populateKernelDescriptorIfNotNull(dst, src.tokens.executionEnvironment); populateKernelDescriptorIfNotNull(dst, src.tokens.samplerStateArray); populateKernelDescriptorIfNotNull(dst, src.tokens.bindingTableState); diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 90a9960951884..c197021984335 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -189,7 +189,7 @@ bool Drm::readSysFsAsString(const std::string &relativeFilePath, std::string &re return false; } - const std::string fileName = devicePath + relativeFilePath; + const std::string &fileName = devicePath + relativeFilePath; int fd = SysCalls::open(fileName.c_str(), O_RDONLY); if (fd < 0) { return false; diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index 2f3d8610b8638..5047e65242615 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -302,7 +302,7 @@ bool Wddm::queryAdapterInfo() { memcpy_s(&gfxPartition, sizeof(gfxPartition), &adapterInfo.GfxPartition, sizeof(GMM_GFX_PARTITIONING)); memcpy_s(&adapterBDF, sizeof(adapterBDF), &adapterInfo.stAdapterBDF, sizeof(ADAPTER_BDF)); - deviceRegistryPath = std::string(adapterInfo.DeviceRegistryPath, sizeof(adapterInfo.DeviceRegistryPath)).c_str(); + deviceRegistryPath = std::string(adapterInfo.DeviceRegistryPath, sizeof(adapterInfo.DeviceRegistryPath)); systemSharedMemory = adapterInfo.SystemSharedMemory; dedicatedVideoMemory = adapterInfo.DedicatedVideoMemory;