From 41e707f9d082a4dd81ee1c4c1a5f28100175f8e5 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Mon, 26 Feb 2024 15:41:19 -0500 Subject: [PATCH] better constructors from `string` for `Identifier` and `Symbol` --- include/rice/rice.hpp | 6 +++--- rice/Identifier.hpp | 2 +- rice/Identifier.ipp | 2 +- rice/cpp_api/Symbol.ipp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/rice/rice.hpp b/include/rice/rice.hpp index 8cc6ecc2..1e6ccc2e 100644 --- a/include/rice/rice.hpp +++ b/include/rice/rice.hpp @@ -3695,7 +3695,7 @@ namespace Rice Identifier(char const* s); //! Construct a new Identifier from a string. - Identifier(std::string const string); + Identifier(std::string const& string); //! Return a string representation of the Identifier. char const* c_str() const; @@ -3729,7 +3729,7 @@ namespace Rice { } - inline Identifier::Identifier(std::string const s) : id_(rb_intern(s.c_str())) + inline Identifier::Identifier(std::string const& s) : id_(rb_intern2(s.c_str(), s.size())) { } @@ -6273,7 +6273,7 @@ namespace Rice } inline Symbol::Symbol(std::string const& s) - : Object(detail::protect(rb_id2sym, detail::protect(rb_intern, s.c_str()))) + : Object(detail::protect(rb_id2sym, detail::protect(rb_intern2, s.c_str(), s.size()))) { } diff --git a/rice/Identifier.hpp b/rice/Identifier.hpp index ea2aba15..2316255a 100644 --- a/rice/Identifier.hpp +++ b/rice/Identifier.hpp @@ -23,7 +23,7 @@ namespace Rice Identifier(char const* s); //! Construct a new Identifier from a string. - Identifier(std::string const string); + Identifier(std::string const& string); //! Return a string representation of the Identifier. char const* c_str() const; diff --git a/rice/Identifier.ipp b/rice/Identifier.ipp index 29adc5f8..eaec8cf2 100644 --- a/rice/Identifier.ipp +++ b/rice/Identifier.ipp @@ -8,7 +8,7 @@ namespace Rice { } - inline Identifier::Identifier(std::string const s) : id_(rb_intern(s.c_str())) + inline Identifier::Identifier(std::string const& s) : id_(rb_intern2(s.c_str(), s.size())) { } diff --git a/rice/cpp_api/Symbol.ipp b/rice/cpp_api/Symbol.ipp index fd420df2..ebe88ddd 100644 --- a/rice/cpp_api/Symbol.ipp +++ b/rice/cpp_api/Symbol.ipp @@ -16,7 +16,7 @@ namespace Rice } inline Symbol::Symbol(std::string const& s) - : Object(detail::protect(rb_id2sym, detail::protect(rb_intern, s.c_str()))) + : Object(detail::protect(rb_id2sym, detail::protect(rb_intern2, s.c_str(), s.size()))) { }