libelektra icon indicating copy to clipboard operation
libelektra copied to clipboard

Make OPMPHM work with zero bytes

Open markus2330 opened this issue 5 years ago • 4 comments

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.

markus2330 avatar Nov 03 '20 14:11 markus2330

@KurtMi ping

markus2330 avatar Jul 21 '21 20:07 markus2330

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:

stale[bot] avatar Jul 30 '22 22:07 stale[bot]

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:

stale[bot] avatar Sep 21 '22 03:09 stale[bot]

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.

kodebach avatar Sep 21 '22 18:09 kodebach

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:

github-actions[bot] avatar Feb 02 '24 01:02 github-actions[bot]

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:

github-actions[bot] avatar Feb 17 '24 01:02 github-actions[bot]