New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$xavi(...) #2337
$xavi(...) #2337
Conversation
3880cb5
to
078d14d
Compare
I could not spot anything on a quick look over the patch. If nobody else wants to still keep it here for review, I am fine to merge it. |
$xavi(WhatEver=>FOo) == $xavi(whatever=>foO)
same as $xavp but case insensitive for keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks all fine, but i noticed that several of the functions are more or less identical to the existing xavp code. This is of course to be expected, as the value works differs only in the case handling. I think it is worthwhile to try if it could be generalized.
What do you think about just using a generic function that gets a function pointer to a comparison or hash function? In some cases only the static core list is necessary. E.g. like this (pseudo-code to the relevant parts);
- static sr_xavp_t *xavi_new_value(str *name, sr_xval_t *val, void * hash_func) { id = hash_func(name->s, name->len); }
- int xavi_add(sr_xavp_t *xavi, sr_xavp_t *list, sr_avp_t core_list) { *core_list = xavi; }
- static sr_xavp_t *xavi_get_internal(str *name, sr_xavp_t **list, int idx, sr_xavp_t **prv, void hash_func, void comp_func) { id = hash_func(..); if (.. && comp_func(...)) }
Using void* function pointers is of course not perfect, but this is what C gives us. In e.g. the DB1 API they are used in different functions in a similar way to prevent a lot of code duplication.
I prefer to have separate functions, instead of going to some generic void* callbacks. Those are hard to track and prone to introduce bugs in existing functional code. The duplicated code should not be really big in size and having new dedicated functions for comparison, etc ... will result also in extra size of the overall code. I actually looked at reusing the xavp code when I implementing xavu recently and the code got a lot of messy IF-ELSE conditions everywhere, functions with extra parameters to indicate what type of variable, etc ... so I reverted and just made dedicated functions, everything afterwards being easier to follow. |
I don't think the usage of function pointers is a big problem, but it was just an idea. If you need to pass to many "switch" type of variables, it gets hard to follow, sure. |
In the case of the two functions you mention, the And my remark was targeting exactly this case, because the functions have like 10 effective lines of code. A wrapper function is like 3 lines of code, with a jump on the stack. So overall it is not a significant gain. It makes sense to have a function for a small number of lines of code, if the function is used in a lot of places, but if it going to be used in 2-3 places, then it has to be a significant number of codes of lines to really worth it. Of course, it can be seen as a personal preference, but I prefer code easier to follow/search/maintain instead of modularising every snippet of code. |
Pre-Submission Checklist
in
doc/
subfolder, the README file is autogenerated)Type Of Change
Checklist:
Description
This change introduces a new type of variable $xavi - eXtended Attribute Value Insensitive case.
It's like a $xavp but keys are case insensitive: