From ce7186cd36e0ce444ce2076b4d232fa509665bbd Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 25 Apr 2017 10:37:55 +0000 Subject: [PATCH] Core: Bits optimized, CtrlLib: ArrayCtrl::WhenColumnSort git-svn-id: svn://ultimatepp.org/upp/trunk@11029 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Hash.cpp | 30 +--------------------- uppsrc/Core/Other.h | 5 +++- uppsrc/Core/Vcont.cpp | 22 ++++++++++++++++ uppsrc/CtrlLib/ArrayCtrl.cpp | 1 + uppsrc/CtrlLib/ArrayCtrl.h | 1 + uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp | 7 +++++ 6 files changed, 36 insertions(+), 30 deletions(-) diff --git a/uppsrc/Core/Hash.cpp b/uppsrc/Core/Hash.cpp index 579704ecd..486e82f18 100644 --- a/uppsrc/Core/Hash.cpp +++ b/uppsrc/Core/Hash.cpp @@ -331,32 +331,4 @@ unsigned GetHashValue0(const double& d) return memhash(&d, sizeof(double)); } -void Bits::Clear() -{ - if(bp) - delete[] bp; - alloc = 0; - bp = NULL; -} - -void Bits::Set(int i, bool b) -{ - ASSERT(i >= 0 && alloc >= 0); - int q = i >> 5; - if(q >= alloc) { - int nalloc = 4 * q / 3 + 1; - dword *nbp = new dword[nalloc]; - if(bp) { - Copy(nbp, bp, bp + alloc); - delete[] bp; - } - Fill(nbp + alloc, nbp + nalloc, (dword)0); - bp = nbp; - alloc = nalloc; - } - i &= 31; - ASSERT(q < alloc); - bp[q] = (bp[q] & ~(1 << i)) | (b << i); -} - -} +} \ No newline at end of file diff --git a/uppsrc/Core/Other.h b/uppsrc/Core/Other.h index ac6469d85..01d90b113 100644 --- a/uppsrc/Core/Other.h +++ b/uppsrc/Core/Other.h @@ -117,10 +117,13 @@ public: class Bits : Moveable { int alloc; dword *bp; + + void Expand(int q); public: void Clear(); - void Set(int i, bool b = true); + void Set(int i, bool b = true) { ASSERT(i >= 0 && alloc >= 0); int q = i >> 5; + if(q >= alloc) Expand(q); i &= 31; bp[q] = (bp[q] & ~(1 << i)) | (b << i); } bool Get(int i) const { ASSERT(i >= 0 && alloc >= 0); int q = i >> 5; return q < alloc ? bp[q] & (1 << (i & 31)) : false; } bool operator[](int i) const { return Get(i); } diff --git a/uppsrc/Core/Vcont.cpp b/uppsrc/Core/Vcont.cpp index 233b39c31..634af60e6 100644 --- a/uppsrc/Core/Vcont.cpp +++ b/uppsrc/Core/Vcont.cpp @@ -83,4 +83,26 @@ thread__ int invector_cache_blki_; thread__ int invector_cache_offset_; thread__ int invector_cache_end_; + +void Bits::Clear() +{ + if(bp) + delete[] bp; + alloc = 0; + bp = NULL; +} + +void Bits::Expand(int q) +{ + int nalloc = 4 * q / 3 + 1; + dword *nbp = new dword[nalloc]; + if(bp) { + Copy(nbp, bp, bp + alloc); + delete[] bp; + } + Fill(nbp + alloc, nbp + nalloc, (dword)0); + bp = nbp; + alloc = nalloc; +} + } diff --git a/uppsrc/CtrlLib/ArrayCtrl.cpp b/uppsrc/CtrlLib/ArrayCtrl.cpp index 6083a2e46..cd76abf4e 100644 --- a/uppsrc/CtrlLib/ArrayCtrl.cpp +++ b/uppsrc/CtrlLib/ArrayCtrl.cpp @@ -2558,6 +2558,7 @@ void ArrayCtrl::DoColumnSort() ColumnSort(sortcolumn, cs); } } + WhenColumnSorted(); } ArrayCtrl& ArrayCtrl::AllSorting() diff --git a/uppsrc/CtrlLib/ArrayCtrl.h b/uppsrc/CtrlLib/ArrayCtrl.h index 901d3dc0f..0dc84dce5 100644 --- a/uppsrc/CtrlLib/ArrayCtrl.h +++ b/uppsrc/CtrlLib/ArrayCtrl.h @@ -357,6 +357,7 @@ public: Event<> WhenCtrlsAction; Event<> WhenScroll; Event<> WhenHeaderLayout; + Event<> WhenColumnSorted; Event WhenLineEnabled; Event WhenLineVisible; diff --git a/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp b/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp index cdc9fba84..d90ff9243 100644 --- a/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp +++ b/uppsrc/CtrlLib/src.tpp/ArrayCtrl$en-us.tpp @@ -2619,6 +2619,13 @@ in the cell editors and react to specific situations accordingly.&] [s5;:ArrayCtrl`:`:WhenHeaderLayout: [_^Callback^ Callback]_[* WhenHeaderLayout]&] [s2; Called when header changes.&] [s3; &] +[s4;%- &] +[s5;:Upp`:`:ArrayCtrl`:`:WhenColumnSorted:%- [_^Upp`:`:Event^ Event]<>_[* WhenColumnSorte +d]&] +[s2; Invoked at the end of DoColumnSort. This allows to react to +user sorting ArrayCtrl by clicking on column header marked as +Sorting.&] +[s3;%- &] [s4; &] [s5;:ArrayCtrl`:`:WhenLineEnabled: [_^Callback2^ Callback2]<[@(0.0.255) int], [@(0.0.255) bool`&]>_[* WhenLineEnabled]&]