Skip to content
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

More code cleanups in stl/src #912

Merged
merged 21 commits into from
Jun 24, 2020

Conversation

StephanTLavavej
Copy link
Member

@StephanTLavavej StephanTLavavej commented Jun 23, 2020

  • Remove unnecessary parentheses in _tolower.cpp, _toupper.cpp, xwctomb.cpp.
    • (Comparisons have well-known higher precedence than logical operators.)
  • Use C++ casts, working towards src: Change C casts to C++ casts #184.
    • Use static_cast for arithmetic types.
    • Use reinterpret_cast for pointers.
    • Use static_cast from void*.
      • (This is providing type information after malloc etc., or restoring type information after going through a void* API. We've stylistically preferred static_cast instead of reinterpret_cast in these scenarios.)
    • static_cast<const char*> when memchr() returns const void*. We don't need to cast away const.
    • We don't need to cast wmemchr() at all; its return type is already correct.
    • Use reinterpret_cast for _Dval*/_Fval*/_Lval* (union type-punning for floating-point). Drop the reinterpret_cast<char*>, which I believe was intended to prevent aliasing optimizations. Remove unnecessary parentheses afterwards. Use const auto (our new convention after a cast).
    • Use const_cast, required by the mismatched type of endptr.
    • In _tolower.cpp, const_cast<short*> then implicitly convert to void*.
    • static_cast and const_cast to locale::facet* in locale.cpp, wlocale.cpp, xlocale.cpp.
      • (These files should probably be unified, and this repeated macro should probably be replaced by a function template, but I haven't attempted to perform such an invasive change here.)
  • In xxxprec.h, don't macroize ldexpf/sqrtf; the UCRT provides them.
  • Change 0 to nullptr.
  • In primitives.h, change __alignof to alignof.
    • (I believe this was attempting to be usable by C translation units, but we compile everything as C++ now. I haven't attempted to change the usage of __max yet.)
  • In filesys.cpp, change wchar_t(0) (which is technically a function-style cast) to L'\0'.
  • In xstoul.cpp, remove preprocessor logic because unsigned long is always 32-bit on our platforms.
  • In locale.cpp, wlocale.cpp, xlocale.cpp, use default template args and name typedefs consistently.
    • (I verified that the types being passed were the defaults.)
  • Fix preprocessor comment in locale0.cpp.
  • Adjust test strings in tr1.
    • (This avoids an astronomical inaccuracy and unnecessary trademark usage.)
    • (The important characteristics, of having an embedded newline and a space, are preserved.)
  • Move a few definitions down to their initializations.
  • Extract a few assignments before if-statements.
  • In mutex.cpp, avoid an elaborated-type-specifier (presumably a relic of when this was a C translation unit).

@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Jun 23, 2020
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner June 23, 2020 01:12
stl/src/locale.cpp Outdated Show resolved Hide resolved
stl/src/mutex.cpp Outdated Show resolved Hide resolved
stl/src/wlocale.cpp Show resolved Hide resolved
stl/src/xdint.cpp Outdated Show resolved Hide resolved
stl/src/xdscale.cpp Outdated Show resolved Hide resolved
stl/src/xdtest.cpp Outdated Show resolved Hide resolved
mutex.cpp: Change 0 to nullptr, avoid elaborated-type-specifier,
move definition to initialization.

xwctomb.cpp: Move definition to initialization, add const.
Copy link
Member

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to note in the commit log that any breakage from removing the double reinterpret_casts is my fault ;)

@StephanTLavavej StephanTLavavej merged commit 4deaf6c into microsoft:master Jun 24, 2020
@StephanTLavavej StephanTLavavej deleted the more_cleanups branch June 24, 2020 08:32
ahanamuk pushed a commit to ahanamuk/STL that referenced this pull request Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants