From 56f699485b1cba3ca3cddcf18c17cc1d536321db Mon Sep 17 00:00:00 2001 From: Omar Ahmed Date: Fri, 3 Nov 2023 15:06:39 +0000 Subject: [PATCH] [UR][OPENCL] eliminate usage of regex in opencl --- source/adapters/opencl/common.hpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/source/adapters/opencl/common.hpp b/source/adapters/opencl/common.hpp index f78710d0df..926c9988f3 100644 --- a/source/adapters/opencl/common.hpp +++ b/source/adapters/opencl/common.hpp @@ -12,7 +12,6 @@ #include #include #include -#include #include /** @@ -72,12 +71,25 @@ class OpenCLVersion { * 'OpenCL' for devices. */ - std::regex Rx("OpenCL ([0-9]+)\\.([0-9]+)"); - std::smatch Match; + std::string_view prefix = "OpenCL "; + size_t versionBegin = Version.find_first_of(" "); + size_t versionEnd = Version.find_first_of(" ", versionBegin + 1); + size_t versionSeparator = Version.find_first_of(".", versionBegin + 1); - if (std::regex_search(Version, Match, Rx) && (Match.size() == 3)) { - OCLMajor = strtoul(Match[1].str().c_str(), nullptr, 10); - OCLMinor = strtoul(Match[2].str().c_str(), nullptr, 10); + bool haveOCLPrefix = + std::equal(prefix.begin(), prefix.end(), Version.begin()); + + if (haveOCLPrefix && versionBegin != std::string::npos && + versionEnd != std::string::npos && + versionSeparator != std::string::npos) { + + std::string versionMajor{Version.begin() + versionBegin + 1, + Version.begin() + versionSeparator}; + std::string versionMinor{Version.begin() + versionSeparator + 1, + Version.begin() + versionEnd}; + + OCLMajor = strtoul(versionMajor.c_str(), nullptr, 10); + OCLMinor = strtoul(versionMinor.c_str(), nullptr, 10); if (!isValid()) { OCLMajor = OCLMinor = 0;