diff --git a/cpp/include/ucxx/address.h b/cpp/include/ucxx/address.h index 4306c85d5..52fae8a8c 100644 --- a/cpp/include/ucxx/address.h +++ b/cpp/include/ucxx/address.h @@ -1,11 +1,11 @@ /** - * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. + * SPDX-FileCopyrightText: Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. * SPDX-License-Identifier: BSD-3-Clause */ #pragma once #include -#include +#include #include @@ -75,7 +75,7 @@ class Address : public Component { * * @returns The `shared_ptr` object. */ - friend std::shared_ptr
createAddressFromString(std::string addressString); + friend std::shared_ptr
createAddressFromString(std::string_view addressString); /** * @brief Get the underlying `ucp_address_t*` handle. @@ -112,7 +112,7 @@ class Address : public Component { * * @returns The underlying `ucp_address_t` handle. */ - [[nodiscard]] std::string getString() const; + [[nodiscard]] std::string_view getString() const; }; } // namespace ucxx diff --git a/cpp/src/address.cpp b/cpp/src/address.cpp index 43ca95077..83198ed9e 100644 --- a/cpp/src/address.cpp +++ b/cpp/src/address.cpp @@ -1,9 +1,9 @@ /** - * SPDX-FileCopyrightText: Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. + * SPDX-FileCopyrightText: Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. * SPDX-License-Identifier: BSD-3-Clause */ #include -#include +#include #include #include @@ -38,11 +38,11 @@ std::shared_ptr
createAddressFromWorker(std::shared_ptr worker) return std::shared_ptr
(new Address(worker, address, length)); } -std::shared_ptr
createAddressFromString(std::string addressString) +std::shared_ptr
createAddressFromString(std::string_view addressString) { - ucp_address_t* address = reinterpret_cast(new char[addressString.length()]); size_t length = addressString.length(); - memcpy(address, addressString.c_str(), length); + ucp_address_t* address = reinterpret_cast(new char[length]); + memcpy(address, addressString.data(), length); return std::shared_ptr
(new Address(nullptr, address, length)); } @@ -50,9 +50,9 @@ ucp_address_t* Address::getHandle() const { return _handle; } size_t Address::getLength() const { return _length; } -std::string Address::getString() const +std::string_view Address::getString() const { - return std::string{reinterpret_cast(_handle), _length}; + return std::string_view{reinterpret_cast(_handle), _length}; } } // namespace ucxx