Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-31068

Reuse duplicate case conversion code in ctype-utf8.c and ctype-ucs2.c

Details

    Description

      Files ctype-utf8.c and ctype-ucs2.c have very similar pieces of the code:

      static inline void
      my_tolower_utf16(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        MY_UNICASE_CHARACTER *page;
        if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
          *wc= page[*wc & 0xFF].tolower;
      }
       
       
      static inline void
      my_toupper_utf16(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        MY_UNICASE_CHARACTER *page;
        if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
          *wc= page[*wc & 0xFF].toupper;
      }
      

       
      static inline void
      my_tolower_utf32(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        MY_UNICASE_CHARACTER *page;
        if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
          *wc= page[*wc & 0xFF].tolower;
      }
       
       
      static inline void
      my_toupper_utf32(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        MY_UNICASE_CHARACTER *page;
        if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
          *wc= page[*wc & 0xFF].toupper;
      }
      

      static inline void
      my_tolower_ucs2(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        MY_UNICASE_CHARACTER *page;
        if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
          *wc= page[*wc & 0xFF].tolower;
      }
       
       
      static inline void
      my_toupper_ucs2(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        MY_UNICASE_CHARACTER *page;
        if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
          *wc= page[*wc & 0xFF].toupper;
      }
      

      static inline void
      my_tolower_utf8mb3(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        MY_UNICASE_CHARACTER *page;
        if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
          *wc= page[*wc & 0xFF].tolower;
      }
       
       
      static inline void
      my_toupper_utf8mb3(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        MY_UNICASE_CHARACTER *page;
        if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
          *wc= page[*wc & 0xFF].toupper;
      }
      

      static inline void
      my_tolower_utf8mb4(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        if (*wc <= uni_plane->maxchar)
        {
          MY_UNICASE_CHARACTER *page;
          if ((page= uni_plane->page[(*wc >> 8)]))
            *wc= page[*wc & 0xFF].tolower;
        }
      }
       
       
      static inline void
      my_toupper_utf8mb4(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        if (*wc <= uni_plane->maxchar)
        {
          MY_UNICASE_CHARACTER *page;
          if ((page= uni_plane->page[(*wc >> 8)]))
            *wc= page[*wc & 0xFF].toupper;
        }
      }
      

      In order to simplify the patch for MDEV-30577 lets move the repeatable code to a shared file ctype-unidata.h:

      /* utf8mb3 and ucs2 share this code */
      static inline void
      my_tolower_unicode_bmp(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        const MY_UNICASE_CHARACTER *page;
        DBUG_ASSERT(*wc <= uni_plane->maxchar);
        if ((page= uni_plane->page[*wc >> 8]))
          *wc= page[*wc & 0xFF].tolower;
      }
       
       
      static inline void
      my_toupper_unicode_bmp(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        const MY_UNICASE_CHARACTER *page;
        DBUG_ASSERT(*wc <= uni_plane->maxchar);
        if ((page= uni_plane->page[*wc >> 8]))
          *wc= page[*wc & 0xFF].toupper;
      }
      

      /* utf8mb4, utf16, utf32 share this code */
      static inline void
      my_tolower_unicode(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        if (*wc <= uni_plane->maxchar)
        {
          const MY_UNICASE_CHARACTER *page;
          if ((page= uni_plane->page[(*wc >> 8)]))
            *wc= page[*wc & 0xFF].tolower;
        }
      }
       
       
      static inline void
      my_toupper_unicode(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
      {
        if (*wc <= uni_plane->maxchar)
        {
          const MY_UNICASE_CHARACTER *page;
          if ((page= uni_plane->page[(*wc >> 8)]))
            *wc= page[*wc & 0xFF].toupper;
        }
      }
      

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov created issue -
            bar Alexander Barkov made changes -
            Field Original Value New Value
            bar Alexander Barkov made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            bar Alexander Barkov made changes -
            Description Files ctype-utf8.c and ctype-ucs2.c have very similar pieces of the code:

            {code:cpp}
            static inline void
            my_tolower_utf16(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_utf16(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}


            {code:cpp}
            static inline void
            my_tolower_utf32(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_utf32(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}



            {code:cpp}
            static inline void
            my_tolower_ucs2(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_ucs2(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}


            {code:cpp}
            static inline void
            my_tolower_utf8mb3(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_utf8mb3(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}


            {code:cpp}
            static inline void
            my_tolower_utf8mb4(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              if (*wc <= uni_plane->maxchar)
              {
                MY_UNICASE_CHARACTER *page;
                if ((page= uni_plane->page[(*wc >> 8)]))
                  *wc= page[*wc & 0xFF].tolower;
              }
            }


            static inline void
            my_toupper_utf8mb4(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              if (*wc <= uni_plane->maxchar)
              {
                MY_UNICASE_CHARACTER *page;
                if ((page= uni_plane->page[(*wc >> 8)]))
                  *wc= page[*wc & 0xFF].toupper;
              }
            }
            {code}


            In order to simplify the patch for MDEV-30577 lets move the repeatable code to a shared file ctype-unidata.h:

            {code:cpp}
            static inline void
            my_tolower_unicode_bmp(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              const MY_UNICASE_CHARACTER *page;
              DBUG_ASSERT(*wc <= uni_plane->maxchar);
              if ((page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_unicode_bmp(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              const MY_UNICASE_CHARACTER *page;
              DBUG_ASSERT(*wc <= uni_plane->maxchar);
              if ((page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}


            {code:cpp}
            static inline void
            my_tolower_unicode(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              if (*wc <= uni_plane->maxchar)
              {
                const MY_UNICASE_CHARACTER *page;
                if ((page= uni_plane->page[(*wc >> 8)]))
                  *wc= page[*wc & 0xFF].tolower;
              }
            }


            static inline void
            my_toupper_unicode(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              if (*wc <= uni_plane->maxchar)
              {
                const MY_UNICASE_CHARACTER *page;
                if ((page= uni_plane->page[(*wc >> 8)]))
                  *wc= page[*wc & 0xFF].toupper;
              }
            }
            {code}
            Files ctype-utf8.c and ctype-ucs2.c have very similar pieces of the code:

            {code:cpp}
            static inline void
            my_tolower_utf16(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_utf16(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}


            {code:cpp}
            static inline void
            my_tolower_utf32(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_utf32(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((*wc <= uni_plane->maxchar) && (page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}



            {code:cpp}
            static inline void
            my_tolower_ucs2(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_ucs2(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}


            {code:cpp}
            static inline void
            my_tolower_utf8mb3(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_utf8mb3(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              MY_UNICASE_CHARACTER *page;
              if ((page= uni_plane->page[(*wc >> 8) & 0xFF]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}


            {code:cpp}
            static inline void
            my_tolower_utf8mb4(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              if (*wc <= uni_plane->maxchar)
              {
                MY_UNICASE_CHARACTER *page;
                if ((page= uni_plane->page[(*wc >> 8)]))
                  *wc= page[*wc & 0xFF].tolower;
              }
            }


            static inline void
            my_toupper_utf8mb4(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              if (*wc <= uni_plane->maxchar)
              {
                MY_UNICASE_CHARACTER *page;
                if ((page= uni_plane->page[(*wc >> 8)]))
                  *wc= page[*wc & 0xFF].toupper;
              }
            }
            {code}


            In order to simplify the patch for MDEV-30577 lets move the repeatable code to a shared file ctype-unidata.h:

            {code:cpp}
            /* utf8mb3 and ucs2 share this code */
            static inline void
            my_tolower_unicode_bmp(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              const MY_UNICASE_CHARACTER *page;
              DBUG_ASSERT(*wc <= uni_plane->maxchar);
              if ((page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].tolower;
            }


            static inline void
            my_toupper_unicode_bmp(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              const MY_UNICASE_CHARACTER *page;
              DBUG_ASSERT(*wc <= uni_plane->maxchar);
              if ((page= uni_plane->page[*wc >> 8]))
                *wc= page[*wc & 0xFF].toupper;
            }
            {code}


            {code:cpp}
            /* utf8mb4, utf16, utf32 share this code */
            static inline void
            my_tolower_unicode(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              if (*wc <= uni_plane->maxchar)
              {
                const MY_UNICASE_CHARACTER *page;
                if ((page= uni_plane->page[(*wc >> 8)]))
                  *wc= page[*wc & 0xFF].tolower;
              }
            }


            static inline void
            my_toupper_unicode(MY_UNICASE_INFO *uni_plane, my_wc_t *wc)
            {
              if (*wc <= uni_plane->maxchar)
              {
                const MY_UNICASE_CHARACTER *page;
                if ((page= uni_plane->page[(*wc >> 8)]))
                  *wc= page[*wc & 0xFF].toupper;
              }
            }
            {code}
            bar Alexander Barkov made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            bar Alexander Barkov made changes -
            issue.field.resolutiondate 2023-04-18 03:25:59.0 2023-04-18 03:25:59.38
            bar Alexander Barkov made changes -
            Fix Version/s 10.10.4 [ 28522 ]
            Fix Version/s 10.11.3 [ 28524 ]
            Fix Version/s 11.1.1 [ 28704 ]
            Fix Version/s 11.0.2 [ 28706 ]
            Fix Version/s 10.10 [ 27530 ]
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Closed [ 6 ]
            bar Alexander Barkov made changes -

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.