mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 16:28:17 +00:00
fix(highlight): allow globals to be cleared
- and reduce heap allocations Fixes #17420
This commit is contained in:
@@ -6758,16 +6758,26 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id)
|
||||
{ NULL, -1, NIL },
|
||||
};
|
||||
|
||||
char hex_name[8];
|
||||
char *name;
|
||||
|
||||
for (int j = 0; cattrs[j].dest; j++) {
|
||||
if (cattrs[j].val != -1) {
|
||||
if (cattrs[j].val < 0) {
|
||||
XFREE_CLEAR(*cattrs[j].dest);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cattrs[j].name.type == kObjectTypeString && cattrs[j].name.data.string.size) {
|
||||
name = cattrs[j].name.data.string.data;
|
||||
} else {
|
||||
snprintf(hex_name, sizeof(hex_name), "#%06x", cattrs[j].val);
|
||||
name = hex_name;
|
||||
}
|
||||
|
||||
if (!*cattrs[j].dest
|
||||
|| STRCMP(*cattrs[j].dest, name) != 0) {
|
||||
xfree(*cattrs[j].dest);
|
||||
if (cattrs[j].name.type == kObjectTypeString && cattrs[j].name.data.string.size) {
|
||||
*cattrs[j].dest = xstrdup(cattrs[j].name.data.string.data);
|
||||
} else {
|
||||
char hex_name[8];
|
||||
snprintf(hex_name, sizeof(hex_name), "#%06x", cattrs[j].val);
|
||||
*cattrs[j].dest = xstrdup(hex_name);
|
||||
}
|
||||
*cattrs[j].dest = xstrdup(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user