Core: SizeBySerialize

git-svn-id: svn://ultimatepp.org/upp/trunk@14892 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-08-24 16:44:35 +00:00
parent 3a3e40bf16
commit 6f1bb82054
3 changed files with 29 additions and 19 deletions

View file

@ -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"

View file

@ -464,6 +464,33 @@ void SerializeGlobalConfigs(Stream& s);
inline void abort() { TerminateProcess(NULL, -1); }
#endif
template <class T>
hash_t HashBySerialize(const T& cont)
{
TimeStop tm;
xxHashStream xxh;
const_cast<T&>(cont).Serialize(xxh);
return xxh.Finish();
}
template <class T>
size_t SizeBySerialize(const T& cont)
{
TimeStop tm;
SizeStream szs;
const_cast<T&>(cont).Serialize(szs);
return szs;
}
template <class T>
bool IsEqualBySerialize(const T& a, const T& b)
{
StringStream sa, sb;
const_cast<T&>(a).Serialize(sa);
const_cast<T&>(b).Serialize(sb);
return sa.GetResult() == sb.GetResult();
}
String Replace(const String& s, const Vector<String>& find, const Vector<String>& replace);
String Replace(const String& s, const VectorMap<String, String>& fr);
WString Replace(const WString& s, const Vector<WString>& find, const Vector<WString>& replace);

View file

@ -21,24 +21,6 @@ void StreamContainer(Stream& s, T& cont)
}
}
template <class T>
hash_t HashBySerialize(const T& cont)
{
TimeStop tm;
xxHashStream xxh;
const_cast<T&>(cont).Serialize(xxh);
return xxh.Finish();
}
template <class T>
bool IsEqualBySerialize(const T& a, const T& b)
{
StringStream sa, sb;
const_cast<T&>(a).Serialize(sa);
const_cast<T&>(b).Serialize(sb);
return sa.GetResult() == sb.GetResult();
}
template <class T>
T * Vector<T>::RawAlloc(int& n)
{