diff --git a/uppsrc/Core/Color.cpp b/uppsrc/Core/Color.cpp index f44793d2b..7441f1806 100644 --- a/uppsrc/Core/Color.cpp +++ b/uppsrc/Core/Color.cpp @@ -119,9 +119,15 @@ Color Blend(Color c1, Color c2, int alpha) min(((a * (c2.GetB() - c1.GetB())) >> 8) + c1.GetB(), 255)); } +#ifdef SVO_VALUE +INITBLOCK { + Value::SvoRegister(); +} +#else INITBLOCK { RichValue::Register(); } +#endif int Grayscale(const Color& c) { diff --git a/uppsrc/Core/Color.h b/uppsrc/Core/Color.h index c9e10517f..8a6e7dddb 100644 --- a/uppsrc/Core/Color.h +++ b/uppsrc/Core/Color.h @@ -52,8 +52,13 @@ public: Color(const Nuller&) { SetNull(); } +#ifdef SVO_VALUE + operator Value() const { return SvoToValue(*this); } + Color(const Value& q) { color = q.Get().color; } +#else operator Value() const { return RichValue(*this); } Color(const Value& q) { color = RichValue::Extract(q).color; } +#endif operator RGBA() const; Color(RGBA rgba); diff --git a/uppsrc/Core/Convert.cpp b/uppsrc/Core/Convert.cpp index f38a6f9a3..c7a377d66 100644 --- a/uppsrc/Core/Convert.cpp +++ b/uppsrc/Core/Convert.cpp @@ -200,7 +200,7 @@ Value StrIntValue(const char *s) int64 q = ScanInt64(s); return IsNull(q) ? ErrorValue(t_("Invalid number !")) : Value(q); } - return Null; + return (int)Null; } Value StrDblValue(const char *s) @@ -209,7 +209,7 @@ Value StrDblValue(const char *s) double q = ScanDouble(s); return IsNull(q) ? ErrorValue(t_("Invalid number !")) : Value(q); } - return Null; + return (double)Null; } Value Scan(dword qtype, const String& text, const Value& def) { diff --git a/uppsrc/Core/Core.h b/uppsrc/Core/Core.h index 58a74f1a9..5db329024 100644 --- a/uppsrc/Core/Core.h +++ b/uppsrc/Core/Core.h @@ -240,7 +240,15 @@ NAMESPACE_UPP #include "Vcont.hpp" #include "Index.hpp" +#ifdef flagSVO_VALUE +#define SVO_VALUE +#endif + +#include "OldValue.h" + #include "Value.h" +#include "ValueUtil.h" + #include "Gtypes.h" #include "Color.h" #include "Complex.h" diff --git a/uppsrc/Core/Core.upp b/uppsrc/Core/Core.upp index 291978961..c8195ede2 100644 --- a/uppsrc/Core/Core.upp +++ b/uppsrc/Core/Core.upp @@ -97,8 +97,13 @@ file Callback.cpp optimize_speed, TimeDate.h, TimeDate.cpp optimize_speed, + OldValue.h, + OldValue.cpp optimize_speed, Value.h, - Value.cpp optimize_speed, + Value.hpp, + Value.cpp, + ValueUtil.h, + ValueUtil.cpp, Complex.h, Format.h, Format.cpp optimize_speed, diff --git a/uppsrc/Core/Defs.h b/uppsrc/Core/Defs.h index 9d32fe4cd..f7142079a 100644 --- a/uppsrc/Core/Defs.h +++ b/uppsrc/Core/Defs.h @@ -317,22 +317,6 @@ extern "C" int COMBINE(i, _length)[]; \ extern "C" int COMBINE(i, _count); \ extern "C" char *COMBINE(i, _files)[]; -int RegisterTypeNo__(const char *type); - -template -int RegisterTypeNo___() -{ - return RegisterTypeNo__(typeid(T).name()); -} - -template -inline int StaticTypeNo() { - static int typeno = -1; - if(typeno < 0) - typeno = RegisterTypeNo___(); - return typeno; -} - class NoCopy { private: NoCopy(const NoCopy&); @@ -520,6 +504,14 @@ inline void Poke16be(const void *ptr, int val) { ((byte *)ptr)[1] = LOBYTE( inline void Poke32be(const void *ptr, int val) { Poke16be(ptr, HIWORD(val)); Poke16be((byte *)ptr + 2, LOWORD(val)); } inline void Poke64be(const void *ptr, int64 val) { Poke32be(ptr, HIDWORD(val)); Poke32be((byte *)ptr + 4, LODWORD(val)); } +#ifdef CPU_LITTLE_ENDIAN +#define MAKE2B(b0, b1) MAKEWORD(b0, b1); +#define MAKE4B(b0, b1, b2, b3) MAKELONG(MAKEWORD(b0, b1), MAKEWORD(b2, b3)) +#else +#define MAKE2B(b0, b1) MAKEWORD(b1, b0); +#define MAKE4B(b0, b1, b2, b3) MAKELONG(MAKEWORD(b2, b3), MAKEWORD(b0, b1)) +#endif + #if defined(CPU_X86) && (defined(COMPILER_GCC) || defined(COMPILER_MSC)) #ifdef COMPILER_GCC #ifdef CPU_64 diff --git a/uppsrc/Core/Gtypes.cpp b/uppsrc/Core/Gtypes.cpp index 7a188f3f5..521eec7da 100644 --- a/uppsrc/Core/Gtypes.cpp +++ b/uppsrc/Core/Gtypes.cpp @@ -2,6 +2,29 @@ NAMESPACE_UPP +#ifdef SVO_VALUE +template +static void sReg() +{ + if(FitsSvoValue()) + Value::SvoRegister(); + else + Value::Register(); +} + +INITBLOCK +{ + sReg(); + sReg(); + sReg(); + sReg(); + sReg(); + sReg(); + Value::Register(); + Value::Register(); + Value::Register(); +} +#else INITBLOCK { Point p; RichValue::Register(); @@ -14,6 +37,7 @@ INITBLOCK { RichValue::Register(); RichValue::Register(); } +#endif //template <> //void Rect_::Union(const Rect_& r) { diff --git a/uppsrc/Core/Gtypes.h b/uppsrc/Core/Gtypes.h index 291110fec..4733498d7 100644 --- a/uppsrc/Core/Gtypes.h +++ b/uppsrc/Core/Gtypes.h @@ -56,7 +56,7 @@ struct Size_ : Moveable< Size_ > { friend T Squared(Size_ a) { return a.cx * a.cx + a.cy * a.cy; } friend double Length(Size_ a) { return hypot(a.cx, a.cy); } - unsigned GetHashValue() const { return UPP::GetHashValue(cx) ^ UPP::GetHashValue(cy); } + unsigned GetHashValue() const { return CombineHash(cx, cy); } String ToString() const; @@ -72,8 +72,13 @@ struct Size_ : Moveable< Size_ > { Size_(const Nuller&) { cx = cy = Null; } +#ifdef SVO_VALUE + operator Value() const { return FitsSvoValue() ? SvoToValue(*this) : RichToValue(*this); } + Size_(const Value& src) { *this = src.Get(); } +#else operator Value() const { return RichValue(*this); } Size_(const Value& src) { *this = RichValue::Extract(src); } +#endif void Serialize(Stream& s) { s % cx % cy; } @@ -158,7 +163,7 @@ struct Point_ : Moveable< Point_ > { friend Point_ Nvl(Point_ a, Point_ b) { return IsNull(a) ? b : a; } - unsigned GetHashValue() const { return UPP::GetHashValue(x) ^ UPP::GetHashValue(y); } + unsigned GetHashValue() const { return CombineHash(x, y); } String ToString() const; @@ -174,8 +179,13 @@ struct Point_ : Moveable< Point_ > { Point_(const Nuller&) { x = y = Null; } +#ifdef SVO_VALUE + operator Value() const { return FitsSvoValue() ? SvoToValue(*this) : RichToValue(*this); } + Point_(const Value& src) { *this = src.Get(); } +#else operator Value() const { return RichValue(*this); } - /*explicit */Point_(const Value& src) { *this = RichValue::Extract(src); } + Point_(const Value& src) { *this = RichValue::Extract(src); } +#endif void Serialize(Stream& s) { s % x % y; } @@ -336,7 +346,7 @@ struct Rect_ : Moveable< Rect_ > { friend const Rect_& Nvl(const Rect_& a, const Rect_& b) { return IsNull(a) ? b : a; } - unsigned GetHashValue() const { return UPP::GetHashValue(left) ^ UPP::GetHashValue(top) ^ UPP::GetHashValue(right) ^ UPP::GetHashValue(bottom); } + unsigned GetHashValue() const { return CombineHash(left, top, right, bottom); } String ToString() const; diff --git a/uppsrc/Core/OldValue.cpp b/uppsrc/Core/OldValue.cpp new file mode 100644 index 000000000..0c48ec9bc --- /dev/null +++ b/uppsrc/Core/OldValue.cpp @@ -0,0 +1,686 @@ +#include "Core.h" + +#ifndef SVO_VALUE + +NAMESPACE_UPP + +#ifndef flagSO +const Nuller Null; +#endif + +#define LTIMING(x) // RTIMING(x) + +unsigned Value::GetHashValue() const { + return IsNull() ? 0 : ptr->GetHashValue(); +} + +Value& Value::operator=(const Value& v) { + if(this == &v) return *this; + ptr->Release(); + ptr = v.ptr; + ptr->Retain(); + return *this; +} + +Value::Value(const Value& v) { + ptr = v.ptr; + ptr->Retain(); +} + +void Value::SetVoidVal() +{ + ptr = &Single(); + ptr->Retain(); +} + +Value::Value() { + SetVoidVal(); +} + +Value::~Value() { + ptr->Release(); +} + +bool Value::operator==(const Value& v) const { + if(ptr == v.ptr) return true; + bool an = IsNull(); + bool bn = v.IsNull(); + if(an || bn) return an && bn; + if(GetType() == v.GetType()) + return ptr->IsEqual(v.ptr); + return ptr->IsPolyEqual(v) || v.ptr->IsPolyEqual(*this); +} + +Value::Value(const String& s) { ptr = new RichValueRep(s); } +Value::Value(const WString& s) { ptr = new RichValueRep(s); } +Value::Value(const char *s) { ptr = new RichValueRep(s); } +Value::Value(int i) { ptr = new RichValueRep(i); } +Value::Value(int64 i) { ptr = new RichValueRep(i); } +Value::Value(double d) { ptr = new RichValueRep(d); } +Value::Value(bool b) { ptr = new RichValueRep(b); } +Value::Value(Date d) { ptr = new RichValueRep(d); } +Value::Value(Time t) { ptr = new RichValueRep