Core: Bits optimized, CtrlLib: ArrayCtrl::WhenColumnSort

git-svn-id: svn://ultimatepp.org/upp/trunk@11029 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-04-25 10:37:55 +00:00
parent 647b4ee789
commit ce7186cd36
6 changed files with 36 additions and 30 deletions

View file

@ -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);
}
}
}

View file

@ -117,10 +117,13 @@ public:
class Bits : Moveable<Bits> {
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); }

View file

@ -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;
}
}

View file

@ -2558,6 +2558,7 @@ void ArrayCtrl::DoColumnSort()
ColumnSort(sortcolumn, cs);
}
}
WhenColumnSorted();
}
ArrayCtrl& ArrayCtrl::AllSorting()

View file

@ -357,6 +357,7 @@ public:
Event<> WhenCtrlsAction;
Event<> WhenScroll;
Event<> WhenHeaderLayout;
Event<> WhenColumnSorted;
Event<int, bool&> WhenLineEnabled;
Event<int, bool&> WhenLineVisible;

View file

@ -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]&]