[libc-commits] [PATCH] D85326: [libc] Add tolower, toupper implementation.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Aug 6 10:42:00 PDT 2020


sivachandra accepted this revision.
sivachandra added inline comments.
This revision is now accepted and ready to land.


================
Comment at: libc/src/ctype/tolower.cpp:20
+  if (internal::isupper(c))
+    return c | 32;
+  return c;
----------------
While this is smart, why should we not prefer a more readable approach like this:

```
return c + 'a' - 'A'; // 'a' - 'A' is a compile time constant so this is effectively just one add instruction.
```


================
Comment at: libc/src/ctype/toupper.cpp:20
+  if (internal::islower(c))
+    return c & 0x5f;
+  return c;
----------------
Same here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85326/new/

https://reviews.llvm.org/D85326



More information about the libc-commits mailing list