Use std::string_view in p_hash() to avoid string copies

This commit is contained in:
Jon Siwek 2021-03-31 13:22:50 -07:00
parent fb33597372
commit d3261238dd

View file

@ -31,6 +31,8 @@
#pragma once #pragma once
#include <string_view>
#include "zeek/Expr.h" #include "zeek/Expr.h"
#include "zeek/Stmt.h" #include "zeek/Stmt.h"
#include "zeek/Traverse.h" #include "zeek/Traverse.h"
@ -49,11 +51,8 @@ using p_hash_type = unsigned long long;
inline p_hash_type p_hash(int val) inline p_hash_type p_hash(int val)
{ return std::hash<int>{}(val); } { return std::hash<int>{}(val); }
inline p_hash_type p_hash(std::string val) inline p_hash_type p_hash(std::string_view val)
{ return std::hash<std::string>{}(val); } { return std::hash<std::string_view>{}(val); }
inline p_hash_type p_hash(const char* val)
{ return p_hash(std::string(val)); }
extern p_hash_type p_hash(const Obj* o); extern p_hash_type p_hash(const Obj* o);
inline p_hash_type p_hash(const IntrusivePtr<Obj>& o) inline p_hash_type p_hash(const IntrusivePtr<Obj>& o)