diff --git a/uppsrc/CodeEditor/CodeEditor.h b/uppsrc/CodeEditor/CodeEditor.h index e18668488..747078f39 100644 --- a/uppsrc/CodeEditor/CodeEditor.h +++ b/uppsrc/CodeEditor/CodeEditor.h @@ -78,6 +78,8 @@ private: int active_annotation; Vector animate; Image status_image; + Color bg_color = Null; + String text; String& PointBreak(int& y); void sPaintImage(Draw& w, int y, int fy, const Image& img); @@ -136,6 +138,9 @@ public: void SetAnimate(const Vector& a) { if(a != animate) { animate = clone(a); Refresh(); } } void StatusImage(const Image& m); + + void Background(Color c) { if(c != bg_color) { bg_color = c; Refresh(); }} + void Text(const String& s) { if(s != text) { text = s; Refresh(); }} EditorBar(); virtual ~EditorBar(); @@ -542,6 +547,8 @@ public: Size GetBarSize() const { return bar.GetSize(); } void HideBar() { bar.Hide(); } void AnimateBar(const Vector& a) { bar.SetAnimate(a); } + void BarColor(Color c) { bar.Background(c); } + void BarText(const String& text) { bar.Text(text); } void Errors(Vector&& errs); diff --git a/uppsrc/CodeEditor/EditorBar.cpp b/uppsrc/CodeEditor/EditorBar.cpp index c589cc79f..69126c7d3 100644 --- a/uppsrc/CodeEditor/EditorBar.cpp +++ b/uppsrc/CodeEditor/EditorBar.cpp @@ -53,11 +53,13 @@ void EditorBar::sPaintImage(Draw& w, int y, int fy, const Image& img) void EditorBar::Paint(Draw& w) { - Color bg = IsDarkTheme() ? GrayColor(70) : SColorLtFace(); + Color bg = Nvl(bg_color, GrayColor(IsDarkTheme() ? 70 : 247)); Size sz = GetSize(); w.DrawRect(0, 0, sz.cx, sz.cy, bg); for(int i = 0; i < animate.GetCount(); i++) w.DrawRect(i, 0, 1, sz.cy, animate[i]); + w.DrawText(0, sz.cy - Zy(10), 900, text, Arial(DPI(20)).Italic(), + GrayColor(IsDarkTheme() ? 100 : 220)); if(!editor) return; for(int pass = 0; pass < 2; pass++) { int fy = editor->GetFontSize().cy; diff --git a/uppsrc/Core/Other.h b/uppsrc/Core/Other.h index 01180a4db..08541e812 100644 --- a/uppsrc/Core/Other.h +++ b/uppsrc/Core/Other.h @@ -214,8 +214,8 @@ public: private: struct Item : Moveable { int prev, next; - int size; // TODO: size_t? - One data; // TODO: Value? + int size; + One data; bool flag; }; @@ -259,8 +259,10 @@ public: template bool RemoveOne(P predicate); template - T& Get(const Maker& m, B before_make, A after_make); - T& Get(const Maker& m) { return Get(m, []{}, []{}); } + T& Get(const Maker& m, B before_make, A after_make, int& sz); + template + T& Get(const Maker& m, B before_make, A after_make) { int sz; return Get(m, before_make, after_make, sz); } + T& Get(const Maker& m) { return Get(m, []{}, []{}); } void Clear(); diff --git a/uppsrc/Core/Other.hpp b/uppsrc/Core/Other.hpp index 3369d847d..ce64b6377 100644 --- a/uppsrc/Core/Other.hpp +++ b/uppsrc/Core/Other.hpp @@ -178,7 +178,7 @@ void LRUCache::ClearCounters() template template -T& LRUCache::Get(const Maker& m, B before_make, A after_make) +T& LRUCache::Get(const Maker& m, B before_make, A after_make, int& sz) { Key k; k.key = m.Key(); @@ -196,9 +196,11 @@ T& LRUCache::Get(const Maker& m, B before_make, A after_make) size += t.size; newsize += t.size; t.flag = flag; + sz = t.size; } else { Item& t = data[q]; + sz = t.size; Unlink(q); if(t.flag != flag) { t.flag = flag; diff --git a/uppsrc/Core/ValueCache.cpp b/uppsrc/Core/ValueCache.cpp index ba1a0f983..d772971e0 100644 --- a/uppsrc/Core/ValueCache.cpp +++ b/uppsrc/Core/ValueCache.cpp @@ -23,52 +23,67 @@ bool IsValueCacheActive() return !sValueCacheFinished; } -int ValueCacheMaxSize = 4000000; - -int ValueCacheMaxSizeLimitLow = 1024*1024; -int ValueCacheMaxSizeLimitHigh = 0; -double ValueCacheRatio = 0.125; +bool ValueCacheFixed = false; +int ValueCacheMaxSize = 0; +int ValueCacheMaxCount = 20000; void AdjustValueCache() { Mutex::Lock __(ValueCacheMutex); + if(ValueCacheFixed) + return; uint64 total, available; GetSystemMemoryStatus(total, available); - if(ValueCacheMaxSizeLimitHigh == 0) - ValueCacheMaxSizeLimitHigh = INT_MAX; - ValueCacheMaxSize = clamp((int)min((int64)(ValueCacheRatio * available), (int64)2000*1024*1024), - ValueCacheMaxSizeLimitLow, ValueCacheMaxSizeLimitHigh); - LLOG("New MakeValue max size " << ValueCacheMaxSize << " high limit " << ValueCacheMaxSizeLimitHigh); + ValueCacheMaxSize = int(available >> 10); + if(!ValueCacheMaxSize && available) { + ValueCacheMaxSize = 128*1024*1024; + } + ValueCacheMaxCount = max(ValueCacheMaxSize / 200, 20000); + LLOG("New MakeValue max size " << ValueCacheMaxSize << " count " << ValueCacheMaxCount); ShrinkValueCache(); } void ShrinkValueCache() { Mutex::Lock __(ValueCacheMutex); - if(!ValueCacheMaxSizeLimitHigh) + if(!ValueCacheMaxSize) AdjustValueCache(); - TheValueCache().Shrink(ValueCacheMaxSize, 20000); + LLOG("MakeValue cache size before shrink: " << TheValueCache().GetSize()); + TheValueCache().Shrink(ValueCacheMaxSize, ValueCacheMaxCount); LLOG("MakeValue cache size after shrink: " << TheValueCache().GetSize()); } -void SetupValueCache(int limit_low, int limit_high, double ratio) +void SetupValueCache(int maxsize, int maxcount) { Mutex::Lock __(ValueCacheMutex); - ValueCacheMaxSizeLimitLow = 1000000; - ValueCacheMaxSizeLimitHigh = 256000000; - ValueCacheRatio = 0.125; + if(maxsize <= 0) { + ValueCacheFixed = false; + AdjustValueCache(); + } + else { + ValueCacheMaxSize = maxsize; + ValueCacheMaxCount = maxcount; + ValueCacheFixed = true; + } } -Value MakeValue(ValueMaker& m) + +Value MakeValueSz(ValueMaker& m, int& sz) { Mutex::Lock __(ValueCacheMutex); LLOG("MakeValue cache size before make: " << TheValueCache().GetSize()); - Value v = TheValueCache().Get(m, [] { ValueCacheMutex.Leave(); }, [] { ValueCacheMutex.Enter(); }); + Value v = TheValueCache().Get(m, [] { ValueCacheMutex.Leave(); }, [] { ValueCacheMutex.Enter(); }, sz); LLOG("MakeValue cache size after make: " << TheValueCache().GetSize()); ShrinkValueCache(); LLOG("-------------"); return v; } +Value MakeValue(ValueMaker& m) +{ + int sz; + return MakeValueSz(m, sz); +} + }; \ No newline at end of file diff --git a/uppsrc/Core/ValueCache.h b/uppsrc/Core/ValueCache.h index 85bafd18e..54b20d639 100644 --- a/uppsrc/Core/ValueCache.h +++ b/uppsrc/Core/ValueCache.h @@ -4,6 +4,7 @@ LRUCache& TheValueCache(); typedef LRUCache::Maker ValueMaker; +Value MakeValueSz(ValueMaker& m, int& sz); Value MakeValue(ValueMaker& m); bool IsValueCacheActive(); @@ -11,7 +12,7 @@ bool IsValueCacheActive(); void AdjustValueCache(); void ShrinkValueCache(); -void SetupValueCache(int limit_low, int limit_high, double ratio); +void SetupValueCache(int maxsize, int maxcount); template int ValueCacheRemove(P what) diff --git a/uppsrc/Core/src.tpp/ValueCache_en-us.tpp b/uppsrc/Core/src.tpp/ValueCache_en-us.tpp index 06fe0c1cb..0d6184333 100644 --- a/uppsrc/Core/src.tpp/ValueCache_en-us.tpp +++ b/uppsrc/Core/src.tpp/ValueCache_en-us.tpp @@ -47,26 +47,25 @@ the program exit.&] [s3;%- &] [s4;%- &] [s5;:Upp`:`:AdjustValueCache`(`):%- [@(0.0.255) void]_[* AdjustValueCache]()&] -[s2; Adjusts the size of cache based on system memory available. -The process is driven by parameters that can be set by SetupValueCache. -Note that CtrlCore (U`+`+ GUI) normally calls this function after -processing every GUI event.&] +[s2; Adjusts cache limits based on system memory available. Maximum +cache size is set to available`_memory / 1024, maximum cached +values count is set to available`_memory / 1024 / 200. Note that +CtrlCore (U`+`+ GUI) normally calls this function after processing +every GUI event.&] [s3;%- &] [s4;%- &] [s5;:Upp`:`:ShrinkValueCache`(`):%- [@(0.0.255) void]_[* ShrinkValueCache]()&] [s2; Maintains the size of cache based on limit computed in the last -AdjustValueCache call.&] +AdjustValueCache call or setup with SetupValueCache.&] [s3;%- &] [s4;%- &] -[s5;:Upp`:`:SetupValueCache`(int`,int`,double`):%- [@(0.0.255) void]_[* SetupValueCache]( -[@(0.0.255) int]_[*@3 limit`_low], [@(0.0.255) int]_[*@3 limit`_high], -[@(0.0.255) double]_[*@3 ratio])&] -[s2; Setups parameters that govern the cache size. [%-*@3 limit`_low] -is low limit `- cache will never be reduced if its consumption -is bellow this limit (default is 4MB). [%-*@3 limit`_high] is upper -limit `- cache size will never grow beyond this limit (default -is 2GB). [%-*@3 ratio] defines how much available system physical -memory can be dedicated to the cache, default is 12.5%.&] +[s5;:Upp`:`:SetupValueCache`(int`,int`):%- [@(0.0.255) void] [* SetupValueCache]([@(0.0.255) i +nt] [*@3 maxsize], [@(0.0.255) int] [*@3 maxcount])&] +[s2; Sets cache limits `- [%-*@3 maxsize] in bytes and [%-*@3 maxcount] +of cached values. If [%-*@3 maxsize] is zero, calls AdjustValueCache +and any further calls to AdjustValueCache adjust it. If [%-*@3 maxsize] +is greater than zero, limits are fixed to [%-*@3 maxsize][%- and +][%-*@3 maxcount].&] [s3; &] [s4;%- &] [s5;:Upp`:`:ValueCacheRemove`(P`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 P]>_[@(0.0.255) i diff --git a/uppsrc/Draw/ImageOp.h b/uppsrc/Draw/ImageOp.h index 997ee4b13..9bb8fa118 100644 --- a/uppsrc/Draw/ImageOp.h +++ b/uppsrc/Draw/ImageOp.h @@ -175,10 +175,7 @@ Image MakeImage(const ImageMaker& m); Image MakeImage(const Image& image, Image (*make)(const Image& image)); void SweepMkImageCache(); - void ClearMakeImageCache(); -void SetMakeImageCacheSize(int m); -void SetMakeImageCacheMax(int m); Image MakeImagePaintOnly(const ImageMaker& m); @@ -223,7 +220,7 @@ Image CachedSetColorKeepAlphaPaintOnly(const Image& img, Color color); Image Magnify(const Image& img, int nx, int ny); Image Minify(const Image& img, int nx, int ny, bool co = false); -Image MinifyCached(const Image& img, int nx, int ny, bool co); +Image MinifyCached(const Image& img, int nx, int ny, bool co = false); Image Upscale2x(const Image& src); Image Downscale2x(const Image& src); diff --git a/uppsrc/Draw/MakeCache.cpp b/uppsrc/Draw/MakeCache.cpp index 906e03348..6014bc277 100644 --- a/uppsrc/Draw/MakeCache.cpp +++ b/uppsrc/Draw/MakeCache.cpp @@ -60,16 +60,6 @@ void SysImageReleased(const Image& img) } } -void SetMakeImageCacheMax(int m) -{ - SetupValueCache(m, 0, 0.125); -} - -void SetMakeImageCacheSize(int m) -{ - SetMakeImageCacheMax(m); -} - void SweepMkImageCache() { AdjustValueCache(); diff --git a/uppsrc/Draw/src.tpp/ImageMaker_en-us.tpp b/uppsrc/Draw/src.tpp/ImageMaker_en-us.tpp index 259393879..7fafbad23 100644 --- a/uppsrc/Draw/src.tpp/ImageMaker_en-us.tpp +++ b/uppsrc/Draw/src.tpp/ImageMaker_en-us.tpp @@ -130,8 +130,9 @@ image). If [%-*@3 co] is true, parallel processing is enabled.&] [s4; &] [s5;:Upp`:`:MinifyCached`(const Upp`:`:Image`&`,int`,int`,bool`): [_^Upp`:`:Image^ Imag e]_[* MinifyCached]([@(0.0.255) const]_[_^Upp`:`:Image^ Image][@(0.0.255) `&]_[*@3 img], -[@(0.0.255) int]_[*@3 nx], [@(0.0.255) int]_[*@3 ny], [@(0.0.255) bool]_[*@3 co])&] -[s2;%% [%-*@3 img] [%-*@3 nx] [%-*@3 ny] [%-*@3 co] .&] +[@(0.0.255) int]_[*@3 nx], [@(0.0.255) int]_[*@3 ny], [@(0.0.255) bool]_[*@3 co]_`=_[@(0.0.255) f +alse])&] +[s2;%% Same as Minify, but cached.&] [s3;%% &] [s4; &] [s5;:Upp`:`:Upscale2x`(const Upp`:`:Image`&`): [_^Upp`:`:Image^ Image]_[* Upscale2x]([@(0.0.255) c diff --git a/uppsrc/Painter/Render.cpp b/uppsrc/Painter/Render.cpp index ab55fb256..1b72d5f00 100644 --- a/uppsrc/Painter/Render.cpp +++ b/uppsrc/Painter/Render.cpp @@ -490,69 +490,3 @@ void BufferPainter::ClipOp() } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/uppsrc/ide/Config.cpp b/uppsrc/ide/Config.cpp index cecb3ac20..88b3307bd 100644 --- a/uppsrc/ide/Config.cpp +++ b/uppsrc/ide/Config.cpp @@ -187,7 +187,7 @@ void Sentinel(Stream& s, const char *txt) void Ide::Serialize(Stream& s) { - int version = 29; + int version = 30; Sentinel(s, "before 12341234"); s.Magic(0x12341234); Sentinel(s, "after magic"); @@ -227,6 +227,8 @@ void Ide::Serialize(Stream& s) s % show_spaces; if(version >= 29) s % block_caret; + if(version >= 30) + s % bar_branch; if(version >= 7) s % warnwhitespace; s % tabs_icons; diff --git a/uppsrc/ide/Setup.cpp b/uppsrc/ide/Setup.cpp index bb542cafd..5f697b956 100644 --- a/uppsrc/ide/Setup.cpp +++ b/uppsrc/ide/Setup.cpp @@ -406,6 +406,7 @@ void Ide::SetupFormat() { (edt.persistent_find_replace, persistent_find_replace) (edt.find_replace_restore_pos, find_replace_restore_pos) (edt.block_caret, block_caret) + (edt.bar_branch, bar_branch) (assist.enabled, LibClangEnabled) (assist.barline, barline) diff --git a/uppsrc/ide/ide.cpp b/uppsrc/ide/ide.cpp index e1e17c66d..655716e16 100644 --- a/uppsrc/ide/ide.cpp +++ b/uppsrc/ide/ide.cpp @@ -74,6 +74,11 @@ void Ide::MakeTitle() title << " [Read Only]"; if(editor.IsDirty()) title << " *"; + if(!bar_branch) + branch = Null; + editor.BarColor(findarg(branch, "", "master", "main") >= 0 ? Null : + IsDarkTheme() ? Color(26, 86, 86) : Color(207, 255, 255)); + editor.BarText(branch); } if(!IsNull(editfile)) for(int i = 0; i < 10; i++) diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index 93e54eea2..4f840fb10 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -655,6 +655,7 @@ public: bool blk0_header = true; bool win_deactivated = false; bool block_caret = false; + bool bar_branch = true; // Formats editor's code with Ide format parameters void FormatJSON_XML(bool xml); diff --git a/uppsrc/ide/ide.lay b/uppsrc/ide/ide.lay index 9820bbbd1..116c967c9 100644 --- a/uppsrc/ide/ide.lay +++ b/uppsrc/ide/ide.lay @@ -567,16 +567,17 @@ LAYOUT(SetupEditorLayout, 544, 344) ITEM(Upp::Option, persistent_find_replace, SetLabel(t_("Do not close Find/Replace dialog automatically")).LeftPosZ(4, 272).TopPosZ(268, 16)) ITEM(Upp::Option, find_replace_restore_pos, SetLabel(t_("Restore position on canceling incremental search")).LeftPosZ(4, 272).TopPosZ(284, 16)) ITEM(Upp::Option, block_caret, SetLabel(t_("Full block caret")).LeftPosZ(4, 272).TopPosZ(300, 16)) + ITEM(Upp::Option, bar_branch, SetLabel(t_("Show git branch in editor bar, change bar color if not main nor master")).LeftPosZ(4, 372).TopPosZ(316, 16)) ITEM(Upp::Option, wordwrap_comments, SetLabel(t_("Wordwrap comments")).LeftPosZ(304, 224).TopPosZ(140, 16)) - ITEM(Upp::Label, dv___25, SetLabel(t_("File Tabs")).LeftPosZ(304, 64).TopPosZ(4, 19)) + ITEM(Upp::Label, dv___26, SetLabel(t_("File Tabs")).LeftPosZ(304, 64).TopPosZ(4, 19)) ITEM(Upp::DropList, filetabs, LeftPosZ(372, 64).TopPosZ(4, 19)) - ITEM(Upp::Label, dv___27, SetLabel(t_("Crosses")).LeftPosZ(304, 64).TopPosZ(24, 19)) + ITEM(Upp::Label, dv___28, SetLabel(t_("Crosses")).LeftPosZ(304, 64).TopPosZ(24, 19)) ITEM(Upp::DropList, tabs_crosses, LeftPosZ(372, 64).TopPosZ(24, 19)) ITEM(Upp::Option, tabs_icons, SetLabel(t_("Icons")).LeftPosZ(304, 132).TopPosZ(44, 16)) ITEM(Upp::Option, tabs_grouping, SetLabel(t_("Group by file folders")).LeftPosZ(304, 132).TopPosZ(60, 16)) ITEM(Upp::Option, tabs_stacking, SetLabel(t_("Stacking")).LeftPosZ(304, 132).TopPosZ(76, 16)) ITEM(Upp::Option, tabs_serialize, SetLabel(t_("Persistent tabs")).LeftPosZ(304, 132).TopPosZ(92, 16)) - ITEM(Upp::Label, dv___33, SetLabel(t_("Spellcheck comments")).LeftPosZ(304, 120).TopPosZ(116, 19)) + ITEM(Upp::Label, dv___34, SetLabel(t_("Spellcheck comments")).LeftPosZ(304, 120).TopPosZ(116, 19)) ITEM(Upp::DropList, spellcheck_comments, LeftPosZ(428, 92).TopPosZ(116, 19)) END_LAYOUT