Home » U++ Library support » U++ Core » DarkThemeCached
DarkThemeCached [message #57072] |
Thu, 20 May 2021 23:11 |
Didier
Messages: 680 Registered: November 2008 Location: France
|
Contributor |
|
|
Hello,
Looking at Pradip's code I saw this DarkThemeCached()
What is it supposed to do ?
Especially this line:
cache.ii = (cache.ii + 1) & (N - 1);
|
|
|
|
|
Re: DarkThemeCached [message #57075 is a reply to message #57074] |
Fri, 21 May 2021 01:52 |
Oblivion
Messages: 1093 Registered: August 2007
|
Senior Contributor |
|
|
To my understanding,
It keeps a little map (icolors = input colors, ocolors = output colors, total: 8 colors);
When you call DarkThemeCached(c)
1) It looks up c in icolors.(keys)
2) If it finds it, it returns the corresponding alternate (dark) theme color, ocolor (values).
3) If it couldn't find it in the keys, then calls DarkTheme(c) to calculate the dark theme color (ocolor). (relatively expensive)
4) Then it puts the new dark theme color variant into the map value and returns it.
Now, probably the confusing part is the index: "cache" structure seems to keep track of the current position, so that it wouldn't overwrite the last cached and used color unless it is necessary. That line with modulo operation is apparently for this purpose.
It will start over from index position 0 only if it is iterated enough ( >= 8 ), i, e. previous lookups failed to find their respective color 'c' value among the keys.
Keep in mind that this is what I see in this piece of code. Not the official explanation.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 21 May 2021 02:06] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Sat Apr 27 18:42:03 CEST 2024
Total time taken to generate the page: 0.04221 seconds
|