libelektra
libelektra copied to clipboard
Make OPMPHM work with zero bytes
opmphmHashfunction clearly takes both a const void * and a size_t. So the hash function has no problem with zero bytes.
The other parts of opmphm.c are tailored to non-zero strings AFAICT, but I also think we just need to make two small changes:
https://github.com/ElektraInitiative/libelektra/blob/5ebc9a4ba5215950f990f7dca948ce310f764079/src/libs/elektra/opmphm.c#L32-L54
Here we need to pass the size of the key name so we don't have to call strlen.
https://github.com/ElektraInitiative/libelektra/blob/5ebc9a4ba5215950f990f7dca948ce310f764079/src/libs/elektra/opmphm.c#L164
https://github.com/ElektraInitiative/libelektra/blob/5ebc9a4ba5215950f990f7dca948ce310f764079/src/libs/elektra/opmphm.c#L182-L191
Here we need to add a getNameSize field to OpmphmInit to avoid strlen.
Both these changes should be pretty simple. Apart from benchmarks/tests these functions are only called in one place each:
https://github.com/ElektraInitiative/libelektra/blob/a5b8684ed10a939b94597e587730ae5b26b09128/src/libs/elektra/keyset.c#L2226
Here we can simply pass the name size.
https://github.com/ElektraInitiative/libelektra/blob/a5b8684ed10a939b94597e587730ae5b26b09128/src/libs/elektra/keyset.c#L2176-L2186
Here we should create a function elektraOpmphmGetStringSize similar to elektraOpmphmGetString and set in the OpmphmInit init.
@KurtMi ping
I mark this issue stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping the issue by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:
I closed this issue now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:
I checked the source code and it's not as simple as switching keyName to keyUnescapedName, but is pretty simple to make the hashmap work with zero-bytes. (details in the top post)
Even if we don't remove the escaped name, we should make this update, because it would avoid the unnecessary strlen calls. We already know the size of all key names.
I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:
I closed this now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart: