From 220f751a03bdcd562ef4f61a6ee608267eb9dabe Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 12 Jul 2016 12:21:46 +0000 Subject: [PATCH] Core: Optimized OutStream, removed DDUMPs git-svn-id: svn://ultimatepp.org/upp/trunk@10032 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Stream.cpp | 11 +++++++++-- uppsrc/Core/Stream.h | 4 +++- uppsrc/CtrlCore/CtrlCore.h | 2 +- uppsrc/CtrlCore/CtrlMt.cpp | 4 ++-- uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp | 13 +++++++------ uppsrc/plugin/lz4/lz4upp.cpp | 6 +----- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/uppsrc/Core/Stream.cpp b/uppsrc/Core/Stream.cpp index 25fbb8e19..414f60fff 100644 --- a/uppsrc/Core/Stream.cpp +++ b/uppsrc/Core/Stream.cpp @@ -147,7 +147,7 @@ bool Stream::GetAll(Huge& h, size_t size) String Stream::Get(int size) { - if(size < 1024*1024) { + if(size < 32 * 1024*1024) { StringBuffer b(size); int n = Get(~b, size); b.SetCount(n); @@ -1126,8 +1126,15 @@ void CompareStream::_Put(int w) { OutStream::OutStream() { + const int bsz = 64 * 1024; + h = new byte[bsz]; buffer = ptr = h; - wrlim = h + sizeof(h); + wrlim = h + bsz; +} + +OutStream::~OutStream() +{ + delete[] h; } void OutStream::_Put(int w) diff --git a/uppsrc/Core/Stream.h b/uppsrc/Core/Stream.h index a55acc507..80c532130 100644 --- a/uppsrc/Core/Stream.h +++ b/uppsrc/Core/Stream.h @@ -521,7 +521,8 @@ public: }; class OutStream : public Stream { - byte h[512]; + byte *h; + protected: virtual void _Put(int w); virtual void _Put(const void *data, dword size); @@ -532,6 +533,7 @@ protected: void Flush(); OutStream(); + ~OutStream(); }; class TeeStream : public OutStream { diff --git a/uppsrc/CtrlCore/CtrlCore.h b/uppsrc/CtrlCore/CtrlCore.h index dc5d5e25f..5da3995c9 100644 --- a/uppsrc/CtrlCore/CtrlCore.h +++ b/uppsrc/CtrlCore/CtrlCore.h @@ -1252,7 +1252,7 @@ public: static void SetTimerGranularity(int ms); - static void Call(Callback cb); + static void Call(Function cb); #ifdef _MULTITHREADED static bool IsShutdownThreads() { return Thread::IsShutdownThreads(); } diff --git a/uppsrc/CtrlCore/CtrlMt.cpp b/uppsrc/CtrlCore/CtrlMt.cpp index 1c5633d87..7900756ae 100644 --- a/uppsrc/CtrlCore/CtrlMt.cpp +++ b/uppsrc/CtrlCore/CtrlMt.cpp @@ -69,13 +69,13 @@ void Ctrl::PerformCall(Ctrl::CallBox *cbox) cbox->sem.Release(); } -void Ctrl::Call(Callback cb) +void Ctrl::Call(Function cb) { if(IsMainThread()) cb(); else { CallBox cbox; - cbox.cb = cb; + cbox.cb << cb; UPP::PostCallback(callback1(PerformCall, &cbox)); WakeUpGuiThread(); int level = LeaveGuiMutexAll(); // Unlock GUI to give main thread chance to handle Call diff --git a/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp b/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp index abdf88845..b9367ae0c 100644 --- a/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp +++ b/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp @@ -2667,17 +2667,18 @@ is available. [*/ This method can only be invoked in the main thread.]&] [s7;i1120;a17; [%-*@3 ms]-|Time to sleep.&] [s3; &] [s4;%- &] -[s5;:Ctrl`:`:Call`(Callback`):%- [@(0.0.255) static] [@(0.0.255) void]_[* Call]([_^Callback^ C -allback]_[*@3 cb])&] +[s5;:Upp`:`:Ctrl`:`:Call`(Upp`:`:Function``):%- [@(0.0.255) static] +[@(0.0.255) void]_[* Call]([_^Upp`:`:Function^ Function]<[@(0.0.255) void]_()>_[*@3 cb])&] [s2; Executes a callback in the main thread (the one responsible for GUI). It works by posting callback into timer queue (with zero delay), then waits its completion using Semaphore. Main GUI thread has to run timer queue management for callback to be executed (by running event`-loop (TopWindow`::Run) or ProcessEvents). -Warning: Call unlocks GuiLock so that the main thread can run -on GUI, this is possible source of race`-conditions. Be prepared -that some other code can run on GUI between call to Call and -cb being executed!&] +Warning: Call temporarily unlocks GuiLock (if locked) so that +the main thread can run on GUI, this is possible source of race`-conditions +(GuiLock is relocked after call completes). Be prepared that +some other code can run on GUI between call to Call and cb being +executed!&] [s3; &] [s4;%- &] [s5;:Ctrl`:`:IsShutdownThreads`(`):%- [@(0.0.255) static] [@(0.0.255) bool]_[* IsShutdownTh diff --git a/uppsrc/plugin/lz4/lz4upp.cpp b/uppsrc/plugin/lz4/lz4upp.cpp index 54fac6e7f..f6eb2c12a 100644 --- a/uppsrc/plugin/lz4/lz4upp.cpp +++ b/uppsrc/plugin/lz4/lz4upp.cpp @@ -66,11 +66,7 @@ void Lz4::FlushOut() if(!pos) return; - int clen; - { - RTIMING("Compress"); - clen = LZ4_compress(buffer, ~outbuf + 4, pos); - } + int clen = LZ4_compress(buffer, ~outbuf + 4, pos); if(clen < 0) { error = true; return;