mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: ValueCache limits simplified, ide: Show branch in editorbar
This commit is contained in:
parent
09b02849d3
commit
547a50d33c
16 changed files with 85 additions and 125 deletions
|
|
@ -78,6 +78,8 @@ private:
|
|||
int active_annotation;
|
||||
Vector<Color> 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<Color>& 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<Color>& a) { bar.SetAnimate(a); }
|
||||
void BarColor(Color c) { bar.Background(c); }
|
||||
void BarText(const String& text) { bar.Text(text); }
|
||||
|
||||
void Errors(Vector<Point>&& errs);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -214,8 +214,8 @@ public:
|
|||
private:
|
||||
struct Item : Moveable<Item> {
|
||||
int prev, next;
|
||||
int size; // TODO: size_t?
|
||||
One<T> data; // TODO: Value?
|
||||
int size;
|
||||
One<T> data;
|
||||
bool flag;
|
||||
};
|
||||
|
||||
|
|
@ -259,8 +259,10 @@ public:
|
|||
template <class P> bool RemoveOne(P predicate);
|
||||
|
||||
template <class B, class A>
|
||||
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 <class B, class A>
|
||||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ void LRUCache<T, K>::ClearCounters()
|
|||
|
||||
template <class T, class K>
|
||||
template <class B, class A>
|
||||
T& LRUCache<T, K>::Get(const Maker& m, B before_make, A after_make)
|
||||
T& LRUCache<T, K>::Get(const Maker& m, B before_make, A after_make, int& sz)
|
||||
{
|
||||
Key k;
|
||||
k.key = m.Key();
|
||||
|
|
@ -196,9 +196,11 @@ T& LRUCache<T, K>::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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -4,6 +4,7 @@ LRUCache<Value>& TheValueCache();
|
|||
|
||||
typedef LRUCache<Value>::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 <class P>
|
||||
int ValueCacheRemove(P what)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -490,69 +490,3 @@ void BufferPainter::ClipOp()
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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++)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue