Skip to content

Commit

Permalink
Use std::size over sizeof/sizeof (microsoft#3090)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <[email protected]>
  • Loading branch information
2 people authored and CaseyCarter committed Oct 6, 2022
1 parent a7e660d commit 835f10d
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion stl/inc/cvt/wbuffer
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace stdext {
}

int_type pbackfail(int_type _Meta = _Traits::eof()) override { // put an element back to stream
if (sizeof(_Myback) / sizeof(_Myback[0]) <= _Nback || _Status == _Wrote) {
if (_STD size(_Myback) <= _Nback || _Status == _Wrote) {
return _Traits::eof(); // nowhere to put back
} else { // enough room, put it back
if (!_Traits::eq_int_type(_Traits::eof(), _Meta)) {
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/cvt/xjis
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace stdext {
}
} else { // search for a valid mapping
unsigned long _Lo = 0;
unsigned long _Hi = sizeof(_Table::_Dbvalid) / sizeof(_Table::_Dbvalid[0]);
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Dbvalid));

while (_Lo < _Hi) { // test midpoint of remaining interval
unsigned long _Mid = (_Hi + _Lo) / 2;
Expand All @@ -72,7 +72,7 @@ namespace stdext {

// search for a valid mapping
unsigned long _Lo = 0;
unsigned long _Hi = sizeof(_Table::_Wvalid) / sizeof(_Table::_Wvalid[0]);
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Wvalid));

while (_Lo < _Hi) { // test midpoint of remaining interval
unsigned long _Mid = (_Hi + _Lo) / 2;
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/cvt/xone_byte
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace stdext {
&& (_Widecode >= 0x100
|| _Table::_Btw[_Widecode - _Table::_Nlow] != _Widecode)) { // search for a valid mapping
unsigned long _Lo = 0;
unsigned long _Hi = sizeof(_Table::_Wvalid) / sizeof(_Table::_Wvalid[0]);
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Wvalid));

while (_Lo < _Hi) { // test midpoint of remaining interval
unsigned long _Mid = (_Hi + _Lo) / 2;
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/cvt/xtwo_byte
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace stdext {
_Widecode =
static_cast<unsigned short>(_Bytecode << 8 | static_cast<unsigned char>(*++_Mid1));
unsigned long _Lo = 0;
unsigned long _Hi = sizeof(_Table::_Dbvalid) / sizeof(_Table::_Dbvalid[0]);
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Dbvalid));

while (_Lo < _Hi) { // test midpoint of remaining interval
unsigned long _Mid = (_Hi + _Lo) / 2;
Expand Down Expand Up @@ -110,7 +110,7 @@ namespace stdext {
&& (_Widecode >= 0x100
|| _Table::_Btw[_Widecode - _Table::_Nlow] != _Widecode)) { // search for a valid mapping
unsigned long _Lo = 0;
unsigned long _Hi = sizeof(_Table::_Wvalid) / sizeof(_Table::_Wvalid[0]);
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Wvalid));

while (_Lo < _Hi) { // test midpoint of remaining interval
unsigned long _Mid = (_Hi + _Lo) / 2;
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/regex
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public:
char_class_type lookup_classname(_Iter _First, _Iter _Last, bool _Icase = false) const {
// map [_First, _Last) to character class mask value
#define _REGEX_CHAR_CLASS_NAME(n, c) \
{ n, L##n, sizeof(n) / sizeof(n[0]) - 1, c }
{ n, L##n, static_cast<unsigned int>(_STD size(n) - 1), c }
static constexpr _Cl_names _Names[] = {
// map class names to numeric constants
_REGEX_CHAR_CLASS_NAME("alnum", _Ch_alnum),
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/xlocbuf
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected:
}

int_type pbackfail(int_type _Meta = _Traits::eof()) override { // put an element back to stream
if (sizeof(_Myback) / sizeof(_Myback[0]) <= _Nback || _Status == _Wrote) {
if (_STD size(_Myback) <= _Nback || _Status == _Wrote) {
return _Traits::eof(); // nowhere to put back
} else { // enough room, put it back
if (!_Traits::eq_int_type(_Traits::eof(), _Meta)) {
Expand Down
2 changes: 1 addition & 1 deletion stl/src/xdateord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _EXTERN_C_UNLESS_PURE

_CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Getdateorder() { // return date order for current locale
wchar_t buf[2] = {0};
GetLocaleInfoEx(___lc_locale_name_func()[LC_TIME], LOCALE_ILDATE, buf, sizeof(buf) / sizeof(buf[0]));
GetLocaleInfoEx(___lc_locale_name_func()[LC_TIME], LOCALE_ILDATE, buf, static_cast<int>(std::size(buf)));

switch (buf[0]) {
case L'0':
Expand Down
8 changes: 5 additions & 3 deletions stl/src/xlsinh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

// _LSinh function

#include <xutility>

#include "xmath.hpp"

_EXTERN_C_UNLESS_PURE

// coefficients
static const long double p[] = {0.0000000000000028486835L, 0.0000000000007646464279L, 0.0000000001605905091647L,
static constexpr long double p[] = {0.0000000000000028486835L, 0.0000000000007646464279L, 0.0000000001605905091647L,
0.0000000250521083436962L, 0.0000027557319224130455L, 0.0001984126984126956009L, 0.0083333333333333336073L,
0.1666666666666666666564L, 1.0000000000000000000001L};

static constexpr size_t NP = sizeof(p) / sizeof(p[0]) - 1;
static constexpr size_t NP = std::size(p) - 1;

_CRTIMP2_PURE long double __CLRCALL_PURE_OR_CDECL _LSinh(long double x, long double y) {
// compute y * sinh(x), |y| <= 1
Expand Down Expand Up @@ -40,7 +42,7 @@ _CRTIMP2_PURE long double __CLRCALL_PURE_OR_CDECL _LSinh(long double x, long dou
if (x < _LRteps._Long_double) {
x *= y; // x tiny
} else if (x < 1.0L) {
long double w = x * x;
const long double w = x * x;

x += x * w * _LPoly(w, p, NP - 1);
x *= y;
Expand Down
4 changes: 3 additions & 1 deletion stl/src/xsinh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// _Sinh function

#include <xutility>

#include "xmath.hpp"

_EXTERN_C_UNLESS_PURE
Expand All @@ -11,7 +13,7 @@ _EXTERN_C_UNLESS_PURE
static constexpr double p[] = {0.0000000001632881, 0.0000000250483893, 0.0000027557344615, 0.0001984126975233,
0.0083333333334816, 0.1666666666666574, 1.0000000000000001};

static constexpr size_t NP = sizeof(p) / sizeof(p[0]) - 1;
static constexpr size_t NP = std::size(p) - 1;

_CRTIMP2_PURE double __CLRCALL_PURE_OR_CDECL _Sinh(double x, double y) { // compute y * sinh(x), |y| <= 1
short neg;
Expand Down

0 comments on commit 835f10d

Please sign in to comment.