From d3261238ddfc321bc1326c92bc19f7af37e55a86 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 31 Mar 2021 13:22:50 -0700 Subject: [PATCH] Use std::string_view in p_hash() to avoid string copies --- src/script_opt/ProfileFunc.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/script_opt/ProfileFunc.h b/src/script_opt/ProfileFunc.h index 6d02f3660e..1016145759 100644 --- a/src/script_opt/ProfileFunc.h +++ b/src/script_opt/ProfileFunc.h @@ -31,6 +31,8 @@ #pragma once +#include + #include "zeek/Expr.h" #include "zeek/Stmt.h" #include "zeek/Traverse.h" @@ -49,11 +51,8 @@ using p_hash_type = unsigned long long; inline p_hash_type p_hash(int val) { return std::hash{}(val); } -inline p_hash_type p_hash(std::string val) - { return std::hash{}(val); } - -inline p_hash_type p_hash(const char* val) - { return p_hash(std::string(val)); } +inline p_hash_type p_hash(std::string_view val) + { return std::hash{}(val); } extern p_hash_type p_hash(const Obj* o); inline p_hash_type p_hash(const IntrusivePtr& o)