commit 5d5ded1: [Project] Use string_view to constexpr variant unpacking

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Jan 22 16:00:19 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-01-18 20:19:51 +0000
URL: https://github.com/rspamd/rspamd/commit/5d5ded1efc2efb1f68b6f1b492b8bee40e0d971a

[Project] Use string_view to constexpr variant unpacking

---
 src/libserver/css/css_selector.hxx | 4 ++--
 src/libserver/css/css_value.hxx    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/libserver/css/css_selector.hxx b/src/libserver/css/css_selector.hxx
index 273ff603e..4c12b3b41 100644
--- a/src/libserver/css/css_selector.hxx
+++ b/src/libserver/css/css_selector.hxx
@@ -47,9 +47,9 @@ struct css_selector {
 		return std::nullopt;
 	}
 
-	std::optional<const std::string> to_string (void) const {
+	constexpr std::optional<const std::string_view> to_string (void) const {
 		if (type == selector_type::SELECTOR_ELEMENT) {
-			return std::get<std::string>(value);
+			return std::string_view(std::get<std::string>(value));
 		}
 		return std::nullopt;
 	}
diff --git a/src/libserver/css/css_value.hxx b/src/libserver/css/css_value.hxx
index e750d775e..fca0e0433 100644
--- a/src/libserver/css/css_value.hxx
+++ b/src/libserver/css/css_value.hxx
@@ -95,9 +95,9 @@ struct css_value {
 		return std::nullopt;
 	}
 
-	std::optional<const std::string> to_string (void) const {
+	constexpr std::optional<std::string_view> to_string (void) const {
 		if (type == css_value_type::CSS_VALUE_STRING) {
-			return std::get<std::string>(value);
+			return std::string_view(std::get<std::string>(value));
 		}
 
 		return std::nullopt;


More information about the Commits mailing list