From 6f1bb82054f05399303b815d7caf204eb04295fe Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 24 Aug 2020 16:44:35 +0000 Subject: [PATCH] Core: SizeBySerialize git-svn-id: svn://ultimatepp.org/upp/trunk@14892 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Core.h | 3 ++- uppsrc/Core/Util.h | 27 +++++++++++++++++++++++++++ uppsrc/Core/Vcont.hpp | 18 ------------------ 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/uppsrc/Core/Core.h b/uppsrc/Core/Core.h index d4b440489..d4812008e 100644 --- a/uppsrc/Core/Core.h +++ b/uppsrc/Core/Core.h @@ -341,6 +341,8 @@ class JsonIO; #include "Color.h" #include "Complex.h" +#include "Hash.h" + #include "Util.h" #include "Profile.h" @@ -351,7 +353,6 @@ class JsonIO; #include "Convert.h" #include "z.h" -#include "Hash.h" #include "Parser.h" #include "JSON.h" diff --git a/uppsrc/Core/Util.h b/uppsrc/Core/Util.h index d8f8693d2..672abcd04 100644 --- a/uppsrc/Core/Util.h +++ b/uppsrc/Core/Util.h @@ -464,6 +464,33 @@ void SerializeGlobalConfigs(Stream& s); inline void abort() { TerminateProcess(NULL, -1); } #endif +template +hash_t HashBySerialize(const T& cont) +{ + TimeStop tm; + xxHashStream xxh; + const_cast(cont).Serialize(xxh); + return xxh.Finish(); +} + +template +size_t SizeBySerialize(const T& cont) +{ + TimeStop tm; + SizeStream szs; + const_cast(cont).Serialize(szs); + return szs; +} + +template +bool IsEqualBySerialize(const T& a, const T& b) +{ + StringStream sa, sb; + const_cast(a).Serialize(sa); + const_cast(b).Serialize(sb); + return sa.GetResult() == sb.GetResult(); +} + String Replace(const String& s, const Vector& find, const Vector& replace); String Replace(const String& s, const VectorMap& fr); WString Replace(const WString& s, const Vector& find, const Vector& replace); diff --git a/uppsrc/Core/Vcont.hpp b/uppsrc/Core/Vcont.hpp index f255bb17f..3e4fee8ed 100644 --- a/uppsrc/Core/Vcont.hpp +++ b/uppsrc/Core/Vcont.hpp @@ -21,24 +21,6 @@ void StreamContainer(Stream& s, T& cont) } } -template -hash_t HashBySerialize(const T& cont) -{ - TimeStop tm; - xxHashStream xxh; - const_cast(cont).Serialize(xxh); - return xxh.Finish(); -} - -template -bool IsEqualBySerialize(const T& a, const T& b) -{ - StringStream sa, sb; - const_cast(a).Serialize(sa); - const_cast(b).Serialize(sb); - return sa.GetResult() == sb.GetResult(); -} - template T * Vector::RawAlloc(int& n) {