Type:
Task
Priority:
Major
Resolution:
Fixed
my_wildcmp_uca_impl() and my_wildcmp_unicode_impl() are 130 lines functions fully repeating each other.
The only difference between them is in two small fragments comparing the subject character and the pattern character for equality.
For example, the second different fragment looks like this:
In my_wildcmp_uca_impl():
if (s_wc == w_wc)
break ;
if ((scan= mb_wc(cs, &s_wc, ( const uchar*)str,
( const uchar*)str_end)) <= 0)
return 1;
if (!my_uca_charcmp(cs,s_wc,w_wc))
break ;
my_wildcmp_unicode_impl():
if ((scan= mb_wc(cs, &s_wc, ( const uchar*)str,
( const uchar*)str_end)) <= 0)
return 1;
if (weights)
{
my_tosort_unicode(weights, &s_wc);
my_tosort_unicode(weights, &w_wc);
}
if (s_wc == w_wc)
break ;
The rest of the code (100+ lines) is fully duplicate, it's hard to maintain it.
Note, under terms of MDEV-31340 we'll need to extend the wildcmp() implementation, to support AS CI comparison style properly for utf8mb4_general1400_as_ci.
Instead of making the code inside my_wildcmp_unicode_impl() more complex to detect which collation style to apply:
binary
AI CI, e.g. utf8mb4_general_ci
AS CI, e.g. utf8mb4_general1400_ai_ci (coming in MDEV-31340 )
it's better to introduce dedicated functions for every collation style.
Proposed changes
The duplicate code should be reused with help of the same approach that we earlier used in MDEV-17474 for strnncoll()-family functions:
The body of the function should be moved to a new shared file ctype-wildcmp.inl
The shared file should be included from multiple places
The code including the shared file will look about like this:
#define MY_FUNCTION_NAME(x) my_ ## x ## _uca_impl
#define MY_MB_WC(cs, pwc, s, e) ((cs)->cset->mb_wc)(cs, pwc, s, e)
#define MY_CHAR_EQ(cs, wc1, wc2) (my_uca_charcmp(cs, wc1, wc2)==0)
#include "ctype-wildcmp.inl"
#define MY_FUNCTION_NAME(x) my_ ## x ## _mb2_or_mb4_impl
#define MY_MB_WC(cs, pwc, s, e) ((cs)->cset->mb_wc)(cs, pwc, s, e)
#define MY_CHAR_EQ(cs, wc1, wc2) my_char_eq_mb2_or_mb4(cs, wc1, wc2)
#include "ctype-wildcmp.inl"
There are no comments yet on this issue.
{"report":{"fcp":980.8000000119209,"ttfb":255.09999999403954,"pageVisibility":"visible","entityId":128274,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"e8c50676-ad11-416f-87d4-25d92299f8c2","navigationType":0,"readyForUser":1061.800000011921,"redirectCount":0,"resourceLoadedEnd":665.1999999880791,"resourceLoadedStart":264.19999998807907,"resourceTiming":[{"duration":14.200000017881393,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":264.19999998807907,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":264.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":278.40000000596046,"responseStart":0,"secureConnectionStart":0},{"duration":14.200000017881393,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":264.59999999403954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":264.59999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":278.80000001192093,"responseStart":0,"secureConnectionStart":0},{"duration":275.19999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":264.90000000596046,"connectEnd":264.90000000596046,"connectStart":264.90000000596046,"domainLookupEnd":264.90000000596046,"domainLookupStart":264.90000000596046,"fetchStart":264.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":290.30000001192093,"responseEnd":540.0999999940395,"responseStart":325.09999999403954,"secureConnectionStart":264.90000000596046},{"duration":399.69999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":265.5,"connectEnd":284,"connectStart":284,"domainLookupEnd":284,"domainLookupStart":284,"fetchStart":265.5,"redirectEnd":0,"redirectStart":0,"requestStart":289.40000000596046,"responseEnd":665.1999999880791,"responseStart":308,"secureConnectionStart":284},{"duration":63.099999994039536,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":265.80000001192093,"connectEnd":265.80000001192093,"connectStart":265.80000001192093,"domainLookupEnd":265.80000001192093,"domainLookupStart":265.80000001192093,"fetchStart":265.80000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":290.69999998807907,"responseEnd":328.90000000596046,"responseStart":327,"secureConnectionStart":265.80000001192093},{"duration":56,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":266,"connectEnd":266,"connectStart":266,"domainLookupEnd":266,"domainLookupStart":266,"fetchStart":266,"redirectEnd":0,"redirectStart":0,"requestStart":291,"responseEnd":322,"responseStart":316.69999998807907,"secureConnectionStart":266},{"duration":57.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":266.19999998807907,"connectEnd":266.19999998807907,"connectStart":266.19999998807907,"domainLookupEnd":266.19999998807907,"domainLookupStart":266.19999998807907,"fetchStart":266.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":291.09999999403954,"responseEnd":323.69999998807907,"responseStart":319.5,"secureConnectionStart":266.19999998807907},{"duration":19.900000005960464,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":266.40000000596046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":266.40000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":286.30000001192093,"responseStart":0,"secureConnectionStart":0},{"duration":56,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":266.5,"connectEnd":266.5,"connectStart":266.5,"domainLookupEnd":266.5,"domainLookupStart":266.5,"fetchStart":266.5,"redirectEnd":0,"redirectStart":0,"requestStart":291.5,"responseEnd":322.5,"responseStart":317.69999998807907,"secureConnectionStart":266.5},{"duration":20.400000005960464,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":266.69999998807907,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":266.69999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":287.09999999403954,"responseStart":0,"secureConnectionStart":0},{"duration":59.79999998211861,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":266.90000000596046,"connectEnd":266.90000000596046,"connectStart":266.90000000596046,"domainLookupEnd":266.90000000596046,"domainLookupStart":266.90000000596046,"fetchStart":266.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":291.69999998807907,"responseEnd":326.69999998807907,"responseStart":320.30000001192093,"secureConnectionStart":266.90000000596046},{"duration":339.7999999821186,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":268.90000000596046,"connectEnd":268.90000000596046,"connectStart":268.90000000596046,"domainLookupEnd":268.90000000596046,"domainLookupStart":268.90000000596046,"fetchStart":268.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":342.40000000596046,"responseEnd":608.6999999880791,"responseStart":599.5,"secureConnectionStart":268.90000000596046},{"duration":341.09999999403954,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":268.90000000596046,"connectEnd":268.90000000596046,"connectStart":268.90000000596046,"domainLookupEnd":268.90000000596046,"domainLookupStart":268.90000000596046,"fetchStart":268.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":401.5,"responseEnd":610,"responseStart":603.4000000059605,"secureConnectionStart":268.90000000596046},{"duration":83,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":668.3000000119209,"connectEnd":668.3000000119209,"connectStart":668.3000000119209,"domainLookupEnd":668.3000000119209,"domainLookupStart":668.3000000119209,"fetchStart":668.3000000119209,"redirectEnd":0,"redirectStart":0,"requestStart":714.9000000059605,"responseEnd":751.3000000119209,"responseStart":749.3000000119209,"secureConnectionStart":668.3000000119209}],"fetchStart":0,"domainLookupStart":13,"domainLookupEnd":20,"connectStart":20,"connectEnd":43,"secureConnectionStart":29,"requestStart":44,"responseStart":255,"responseEnd":268,"domLoading":259,"domInteractive":1115,"domContentLoadedEventStart":1115,"domContentLoadedEventEnd":1157,"domComplete":1547,"loadEventStart":1547,"loadEventEnd":1547,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1100.0999999940395},{"name":"bigPipe.sidebar-id.end","time":1100.800000011921},{"name":"bigPipe.activity-panel-pipe-id.start","time":1101},{"name":"bigPipe.activity-panel-pipe-id.end","time":1101.5},{"name":"activityTabFullyLoaded","time":1165.5}],"measures":[],"correlationId":"28444359483115","effectiveType":"4g","downlink":9.9,"rtt":0,"serverDuration":135,"dbReadsTimeInMs":17,"dbConnsTimeInMs":26,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}