git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] [GSOC] ref-filter: add %(raw) atom

From
ZheNing Hu <adlternative@gmail.com>
Date
May 30, 2021, 06:29 UTC
Message-ID
<CAOLTT8TEkrxAgHvkCVXZDQpn0xSQAe_y7uMF89Q4QWwVd7MDcA@mail.gmail.com>
In-Reply-To
<60b25ca7a01c2_265088208af@natae.notmuch>
Felipe Contreras <felipe.contreras@gmail.com> 于2021年5月29日周六 下午11:24写道:
Show 26 quoted lines
>
> Phillip Wood wrote:
> > On 27/05/2021 17:36, Felipe Contreras wrote:
> > > ZheNing Hu via GitGitGadget wrote:
> > > [...]
> > >> +static int memcasecmp(const void *vs1, const void *vs2, size_t n)
> > >
> > > Why void *? We can delcare as char *.
> >
> > If you look at how this function is used you'll see
> >       int (*cmp_fn)(const void *, const void *, size_t);
> >       cmp_fn = s->sort_flags & REF_SORTING_ICASE
> >                       ? memcasecmp : memcmp;
>
> Yeah, but why?
>
> We know we are comparing two char *. Presumably the reason is that
> memcmp and memcasecmp use void *, but that could be remedied with:
>
>         cmp_fn = (int (*)(const char *, const char *, size_t))memcmp;
>
> That way the same cmp_fn could be used for the two cases.
>
> Either way I don't care particularly much. It also could be possible to
> use void * and do the casting in tolower().
>

I agree with Phillip's point of view here: It would be better for memcasecmp and memcmp to be consistent.

Show 8 quoted lines
> > > (and I personally prefer lower to upper)
> >
> > We should be using tolower() as that is what POSIX specifies for
> > strcasecmp() [1] which we are trying to emulate and there are cases[2] where
> >       (tolower(c1) == tolower(c2)) != (toupper(c1) == toupper(c2))
>
> That's true.
>
How about something like this:
 static int memcasecmp(const void *vs1, const void *vs2, size_t n)
 {
-       size_t i;
-       const char *s1 = (const char *)vs1;
-       const char *s2 = (const char *)vs2;
-
-       for (i = 0; i < n; i++) {
-               unsigned char u1 = s1[i];
-               unsigned char u2 = s2[i];
-               int U1 = toupper (u1);
-               int U2 = toupper (u2);
-               int diff = (UCHAR_MAX <= INT_MAX ? U1 - U2
-                       : U1 < U2 ? -1 : U2 < U1);
+       const char *s1 = (const void *)vs1;
+       const char *s2 = (const void *)vs2;
+       const char *end = s1 + n;
+
+       for (; s1 < end; s1++, s2++) {
+               int diff = tolower(*s1) - tolower(*s2);
                if (diff)
                        return diff;
        }
}
> --
> Felipe Contreras

Thanks. -- ZheNing Hu

Previous: Phillip WoodNext: Phillip Wood
Message 10 of 41 in “[GSOC] ref-filter: add %(raw) atom”
  1. 0/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, May 27, 2021
  2. 1/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, May 27, 2021
  3. Felipe ContrerasMay 27, 2021
  4. ZheNing HuMay 28, 2021
  5. Felipe ContrerasMay 28, 2021
  6. ZheNing HuMay 30, 2021
  7. Phillip WoodMay 29, 2021
  8. Felipe ContrerasMay 29, 2021
  9. Phillip WoodMay 29, 2021
  10. ZheNing HuMay 30, 2021
  11. Phillip WoodMay 30, 2021
  12. ZheNing HuMay 31, 2021
  13. Felipe ContrerasMay 31, 2021
  14. ZheNing HuMay 30, 2021
  15. Phillip WoodMay 30, 2021
  16. Junio C HamanoMay 28, 2021
  17. ZheNing HuMay 28, 2021
  18. Felipe ContrerasMay 28, 2021
  19. ZheNing HuMay 30, 2021
  20. 2/2 [GSOC] ref-filter: add %(header) atomZheNing Hu via GitGitGadget, May 27, 2021
  21. Felipe ContrerasMay 27, 2021
  22. Junio C HamanoMay 28, 2021
  23. Junio C HamanoMay 28, 2021
  24. ZheNing HuMay 28, 2021
  25. Felipe ContrerasMay 27, 2021
  26. 0/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, May 30, 2021
  27. 1/2 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, May 30, 2021
  28. Junio C HamanoMay 31, 2021
  29. 2/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, May 30, 2021
  30. Junio C HamanoMay 31, 2021
  31. ZheNing HuMay 31, 2021
  32. Junio C HamanoJun 1, 2021
  33. ZheNing HuJun 1, 2021
  34. Junio C HamanoMay 31, 2021
  35. ZheNing HuMay 31, 2021
  36. Junio C HamanoJun 1, 2021
  37. ZheNing HuJun 1, 2021
  38. Johannes SchindelinJun 1, 2021
  39. Junio C HamanoMay 31, 2021
  40. Felipe ContrerasMay 31, 2021
  41. ZheNing HuJun 1, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.