mirror of
https://github.com/opentx/opentx.git
synced 2025-07-17 13:25:20 +03:00
* [Horus] Fixes #3775 Quick fix ... comments welcome :) * Better hash function for strings * One comment, one! * One comment, one!
This commit is contained in:
parent
883ab9a937
commit
481df9ee3d
3 changed files with 22 additions and 10 deletions
|
@ -25,9 +25,9 @@ class ModelBitmapWidget: public Widget
|
||||||
public:
|
public:
|
||||||
ModelBitmapWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
ModelBitmapWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||||
Widget(factory, zone, persistentData),
|
Widget(factory, zone, persistentData),
|
||||||
buffer(NULL)
|
buffer(NULL),
|
||||||
|
deps_hash(0)
|
||||||
{
|
{
|
||||||
memset(bitmapFilename, 255, sizeof(bitmapFilename));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~ModelBitmapWidget()
|
virtual ~ModelBitmapWidget()
|
||||||
|
@ -65,11 +65,12 @@ class ModelBitmapWidget: public Widget
|
||||||
|
|
||||||
virtual void refresh()
|
virtual void refresh()
|
||||||
{
|
{
|
||||||
if (memcmp(bitmapFilename, g_model.header.bitmap, sizeof(g_model.header.bitmap)) != 0 ||
|
uint32_t new_hash = hash(g_model.header.bitmap, sizeof(g_model.header.bitmap));
|
||||||
memcmp(modelName, g_model.header.name, sizeof(g_model.header.name)) != 0) {
|
new_hash ^= hash(g_model.header.name, sizeof(g_model.header.name));
|
||||||
|
new_hash ^= hash(g_eeGeneral.themeName, sizeof(g_eeGeneral.themeName));
|
||||||
|
if (new_hash != deps_hash) {
|
||||||
|
deps_hash = new_hash;
|
||||||
refreshBuffer();
|
refreshBuffer();
|
||||||
memcpy(bitmapFilename, g_model.header.bitmap, sizeof(g_model.header.bitmap));
|
|
||||||
memcpy(modelName, g_model.header.name, sizeof(g_model.header.name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
|
@ -78,9 +79,8 @@ class ModelBitmapWidget: public Widget
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char bitmapFilename[sizeof(g_model.header.bitmap)];
|
|
||||||
char modelName[sizeof(g_model.header.name)];
|
|
||||||
BitmapBuffer * buffer;
|
BitmapBuffer * buffer;
|
||||||
|
uint32_t deps_hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseWidgetFactory<ModelBitmapWidget> modelBitmapWidget("ModelBmp", NULL);
|
BaseWidgetFactory<ModelBitmapWidget> modelBitmapWidget("ModelBmp", NULL);
|
||||||
|
|
|
@ -99,7 +99,6 @@ int8_t calcRESXto100(int16_t x)
|
||||||
return (x*25) >> 8;
|
return (x*25) >> 8;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HELI) || defined(FRSKY_HUB) || defined(CPUARM)
|
#if defined(HELI) || defined(FRSKY_HUB) || defined(CPUARM)
|
||||||
uint16_t isqrt32(uint32_t n)
|
uint16_t isqrt32(uint32_t n)
|
||||||
{
|
{
|
||||||
|
@ -172,3 +171,16 @@ void getGpsDistance()
|
||||||
telemetryData.hub.maxGpsDistance = telemetryData.hub.gpsDistance;
|
telemetryData.hub.maxGpsDistance = telemetryData.hub.gpsDistance;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CPUARM)
|
||||||
|
// djb2 hash algorithm
|
||||||
|
uint32_t hash(const void * ptr, uint32_t size)
|
||||||
|
{
|
||||||
|
const uint8_t * data = (const uint8_t *)ptr;
|
||||||
|
uint32_t hash = 5381;
|
||||||
|
for (uint32_t i=0; i<size; i++) {
|
||||||
|
hash = ((hash << 5) + hash) + data[i]; /* hash * 33 + c */
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -897,7 +897,7 @@ void checkModelIdUnique(uint8_t index, uint8_t module);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
|
uint32_t hash(const void * ptr, uint32_t size);
|
||||||
inline int divRoundClosest(const int n, const int d)
|
inline int divRoundClosest(const int n, const int d)
|
||||||
{
|
{
|
||||||
if (d == 0)
|
if (d == 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue