From bbdc24dfab1241810e4934a20a85b4de39b5e11f Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 8 Aug 2019 20:58:34 +0000 Subject: [PATCH] Core: clone/pick refinements, heap refinements git-svn-id: svn://ultimatepp.org/upp/trunk@13525 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Heap.h | 5 +++++ uppsrc/Core/Vcont.h | 1 + uppsrc/Core/src.tpp/Array_en-us.tpp | 33 +++++++---------------------- uppsrc/Core/src.tpp/Heap_en-us.tpp | 4 +++- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/uppsrc/Core/Heap.h b/uppsrc/Core/Heap.h index 9755eee1c..cd6a42746 100644 --- a/uppsrc/Core/Heap.h +++ b/uppsrc/Core/Heap.h @@ -9,6 +9,11 @@ struct MemoryOptions { // sizes are in KB ~MemoryOptions(); // sets options }; +enum { + UPP_HEAP_ALIGNMENT = 16, + UPP_HEAP_MINBLOCK = 32, +}; + #ifdef UPP_HEAP void *MemoryAllocPermanent(size_t size); diff --git a/uppsrc/Core/Vcont.h b/uppsrc/Core/Vcont.h index b82281dd6..521626678 100644 --- a/uppsrc/Core/Vcont.h +++ b/uppsrc/Core/Vcont.h @@ -344,6 +344,7 @@ public: void Swap(Array& b) { Swap(vector, b.vector); } Array& operator<<(const T& x) { Add(x); return *this; } + Array& operator<<(T&& x) { Add(pick(x)); return *this; } Array& operator<<(T *newt) { Add(newt); return *this; } void Serialize(Stream& s) { StreamContainer(s, *this); } diff --git a/uppsrc/Core/src.tpp/Array_en-us.tpp b/uppsrc/Core/src.tpp/Array_en-us.tpp index 2a10d0e89..a0624b939 100644 --- a/uppsrc/Core/src.tpp/Array_en-us.tpp +++ b/uppsrc/Core/src.tpp/Array_en-us.tpp @@ -522,16 +522,17 @@ rray][@(0.0.255) `&]_[*@3 b])&] [s4;%- &] [s5;:Array`:`:operator`<`<`(const T`&`):%- [_^topic`:`/`/Core`/src`/Array`$en`-us`#Array`:`:class^ A rray][@(0.0.255) `&]_[* operator<<]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] -[s2; Operator replacement of [* void Add(const T`&x)]. By returning -a reference to the Array it allows adding more elements in a -single expression, thus e.g. allowing to construct a temporary -Array as part of an expression like Foo((Array() << 1 << -2 << 4)).&] +[s5;:Upp`:`:Array`:`:operator`<`<`(T`&`&`):%- [_^Upp`:`:Array^ Array][@(0.0.255) `&]_[* ope +rator<<]([*@4 T][@(0.0.255) `&`&]_[*@3 x])&] +[s2; Operator replacement of [* Add]. By returning a reference to the +Array it allows adding more elements in a single expression, +thus e.g. allowing to construct a temporary Array as part of +an expression like Foo((Array() << 1 << 2 << 4)).&] [s6; Requires T to have deep copy constructor.&] [s6; Invalidates iterators to the Array.&] -[s7; [*C@3 x]-|The value that is copied to newly created element.&] +[s7; [*C@3 x]-|The value that is transferred to newly created element.&] [s7; [*/ Return value]-|Reference to the Array (`*this).&] -[s3;%- &] +[s3; &] [s4;%- &] [s5;:Array`:`:operator`<`<`(T`*`):%- [_^topic`:`/`/Core`/src`/Array`$en`-us`#Array`:`:class^ A rray][@(0.0.255) `&]_[* operator<<]([*@4 T]_`*[*@3 newt])&] @@ -544,24 +545,6 @@ an expression like Foo((Array() << new Bar << new DerivedFromBar)).&] [s7; [*/ Return value]-|Reference to the Array (`*this).&] [s3;%- &] [s4;%- &] -[s5;:Array`:`:operator`|`(pick`_ T`&`):%- [_^topic`:`/`/Core`/src`/Array`$en`-us`#Array`:`:class^ A -rray][@(0.0.255) `&]_[* operator`|]([@(0.128.128) pick`_]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] -[s2; Operator replacement of [* void AddPick(pick`_ T`&x)]. By returning -a reference to the Array it allows adding more elements in a -single expression, thus e.g. allowing to construct a temporary -Array as part of an expression.&] -[s6; Requires T to have pick constructor.&] -[s6; Invalidates iterators to the Array.&] -[s7; [*C@3 x]-|Source instance of T that is to be picked.&] -[s7; [*/ Return value]-|Reference to Array (`*this).&] -[s3;%- &] -[s4;%- &] -[s5;:Array`:`:IsPicked`(`)const:%- [@(0.0.255) bool]_[* IsPicked]()_[@(0.0.255) const]&] -[s2; Returns [* true] if the Array is in picked state.&] -[s7; [*/ Return value]-|[* true] if the Array is in picked state, [* false] -otherwise.&] -[s3;%- &] -[s4;%- &] [s5;:Array`:`:Serialize`(Stream`&`):%- [@(0.0.255) void]_[* Serialize]([_^topic`:`/`/Core`/src`/Stream`$en`-us`#Stream`:`:class^ S tream][@(0.0.255) `&]_[*@3 s])&] [s2; Serializes the content of the Array to/from the Stream. Works diff --git a/uppsrc/Core/src.tpp/Heap_en-us.tpp b/uppsrc/Core/src.tpp/Heap_en-us.tpp index 6b3fe2b37..956cd61e1 100644 --- a/uppsrc/Core/src.tpp/Heap_en-us.tpp +++ b/uppsrc/Core/src.tpp/Heap_en-us.tpp @@ -31,7 +31,9 @@ checks.&] ize`_t][@(0.0.255) `&]_[*@3 size])&] [s2;%% Allocates a memory block of at least [%-*@3 size] bytes. [%-*@3 size] is set to the real number of bytes in the block that can be used -by an application.&] +by an application. Guaranteed alignment is specified in [* UPP`_HEAP`_ALIGNMENT] +constant (currently 16). The minimal real size of returned block +in release mode is [* UPP`_HEAP`_MINBLOCK] (currently 32).&] [s3;%% &] [s4; &] [s5;:Upp`:`:MemoryAlloc`(size`_t`): [@(0.0.255) void]_`*[* MemoryAlloc]([_^size`_t^ size`_t