Skip to content

Commit b0b753b

Browse files
committed
const/constexpr/noexcept in Int128
1 parent b238107 commit b0b753b

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

src/common/Int128.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ using namespace Firebird;
4747
namespace {
4848

4949
const CInt128 i64max(MAX_SINT64), i64min(MIN_SINT64);
50-
const double p2_32 = 4294967296.0;
50+
constexpr double p2_32 = 4294967296.0;
5151
const I128limit i128limit;
5252
const CInt128 minus1(-1);
5353

@@ -166,7 +166,7 @@ void Int128::toString(int scale, string& to) const
166166
}
167167
else
168168
{
169-
unsigned posScale = -scale;
169+
const unsigned posScale = -scale;
170170
if (posScale > to.length())
171171
{
172172
string tmp(posScale - to.length(), '0');
@@ -241,12 +241,12 @@ Int128 Int128::div(Int128 op2, int scale) const
241241
return op1;
242242
}
243243

244-
void Int128::zerodivide()
244+
[[noreturn]] void Int128::zerodivide()
245245
{
246246
(Arg::Gds(isc_arith_except) << Arg::Gds(isc_exception_integer_divide_by_zero)).raise();
247247
}
248248

249-
void Int128::overflow()
249+
[[noreturn]] void Int128::overflow()
250250
{
251251
(Arg::Gds(isc_arith_except) << Arg::Gds(isc_exception_integer_overflow)).raise();
252252
}
@@ -288,7 +288,7 @@ CInt128 MAX_Int128(CInt128::MkMax);
288288
namespace {
289289

290290
const CInt128 i64max(MAX_SINT64), i64min(MIN_SINT64);
291-
const double p2_32 = 4294967296.0;
291+
constexpr double p2_32 = 4294967296.0;
292292
const I128limit i128limit;
293293
const CInt128 minus1(-1);
294294

@@ -425,7 +425,7 @@ void Int128::toString(int scale, unsigned length, char* to) const
425425
void Int128::toString(int scale, string& to) const
426426
{
427427
v.ToStringBase(to);
428-
bool sgn = to[0] == '-';
428+
const bool sgn = to[0] == '-';
429429
if (sgn)
430430
to.erase(0, 1);
431431

@@ -444,7 +444,7 @@ void Int128::toString(int scale, string& to) const
444444
}
445445
else
446446
{
447-
unsigned posScale = -scale;
447+
const unsigned posScale = -scale;
448448
if (posScale > to.length())
449449
{
450450
string tmp(posScale - to.length(), '0');
@@ -511,7 +511,7 @@ Int128 Int128::div(Int128 op2, int scale) const
511511

512512
// Scale op1 by as many of the needed powers of 10 as possible without an overflow.
513513
CInt128 op1(*this);
514-
int sign1 = op1.sign();
514+
const int sign1 = op1.sign();
515515
while ((scale < 0) && (sign1 >= 0 ? op1.compare(MAX_BY10) <= 0 : op1.compare(MIN_BY10) >= 0))
516516
{
517517
op1 *= 10;
@@ -537,17 +537,17 @@ Int128 Int128::div(Int128 op2, int scale) const
537537
return op1;
538538
}
539539

540-
void Int128::getTable32(unsigned* dwords) const
540+
void Int128::getTable32(unsigned* dwords) const noexcept
541541
{
542542
static_assert((sizeof(v.table[0]) == 4) || (sizeof(v.table[0]) == 8),
543543
"Unsupported size of integer in ttmath");
544544

545-
if (sizeof(v.table[0]) == 4)
545+
if constexpr (sizeof(v.table[0]) == 4)
546546
{
547547
for (int i = 0; i < 4; ++i)
548548
dwords[i] = v.table[i];
549549
}
550-
else if (sizeof(v.table[0]) == 8)
550+
else if constexpr (sizeof(v.table[0]) == 8)
551551
{
552552
for (int i = 0; i < 2; ++i)
553553
{
@@ -557,12 +557,12 @@ void Int128::getTable32(unsigned* dwords) const
557557
}
558558
}
559559

560-
void Int128::setTable32(const unsigned* dwords)
560+
void Int128::setTable32(const unsigned* dwords) noexcept
561561
{
562562
static_assert((sizeof(v.table[0]) == 4) || (sizeof(v.table[0]) == 8),
563563
"Unsupported size of integer in ttmath");
564564

565-
if (sizeof(v.table[0]) == 4)
565+
if constexpr (sizeof(v.table[0]) == 4)
566566
{
567567
for (int i = 0; i < 4; ++i)
568568
v.table[i] = dwords[i];
@@ -582,7 +582,7 @@ Int128 Int128::operator&=(FB_UINT64 mask)
582582
{
583583
v.table[0] &= mask;
584584
unsigned i = 1;
585-
if (sizeof(v.table[0]) == 4)
585+
if constexpr (sizeof(v.table[0]) == 4)
586586
{
587587
i = 2;
588588
v.table[1] &= (mask >> 32);
@@ -602,12 +602,12 @@ Int128 Int128::operator&=(ULONG mask)
602602
return *this;
603603
}
604604

605-
void Int128::zerodivide()
605+
[[noreturn]] void Int128::zerodivide()
606606
{
607607
(Arg::Gds(isc_arith_except) << Arg::Gds(isc_exception_integer_divide_by_zero)).raise();
608608
}
609609

610-
void Int128::overflow()
610+
[[noreturn]] void Int128::overflow()
611611
{
612612
(Arg::Gds(isc_arith_except) << Arg::Gds(isc_exception_integer_overflow)).raise();
613613
}

src/common/Int128.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Decimal64;
4646
class Decimal128;
4747
struct DecimalStatus;
4848

49-
class Int128 //: public Decimal128Base
49+
class Int128
5050
{
5151
public:
5252
#if SIZEOF_LONG < 8
@@ -305,26 +305,26 @@ class Int128 //: public Decimal128Base
305305

306306
void setScale(int scale);
307307

308-
UCHAR* getBytes()
308+
UCHAR* getBytes() noexcept
309309
{
310310
return (UCHAR*)(&v);
311311
}
312312

313-
static const unsigned BIAS = 128;
314-
static const unsigned PMAX = 38;
313+
static constexpr unsigned BIAS = 128;
314+
static constexpr unsigned PMAX = 38;
315315

316316
ULONG makeIndexKey(vary* buf, int scale);
317317

318-
static ULONG getIndexKeyLength()
318+
static ULONG getIndexKeyLength() noexcept
319319
{
320320
return 19;
321321
}
322322

323323
protected:
324324
absl::int128 v;
325325

326-
static void overflow();
327-
static void zerodivide();
326+
[[noreturn]] static void overflow();
327+
[[noreturn]] static void zerodivide();
328328

329329
Int128 set(const char* value);
330330
};
@@ -368,7 +368,7 @@ class Decimal64;
368368
class Decimal128;
369369
struct DecimalStatus;
370370

371-
class Int128 //: public Decimal128Base
371+
class Int128
372372
{
373373
public:
374374
#if SIZEOF_LONG < 8
@@ -556,30 +556,30 @@ class Int128 //: public Decimal128Base
556556
*remainder = rem;
557557
}
558558

559-
void getTable32(unsigned* dwords) const; // internal data in per-32bit form
560-
void setTable32(const unsigned* dwords);
559+
void getTable32(unsigned* dwords) const noexcept; // internal data in per-32bit form
560+
void setTable32(const unsigned* dwords) noexcept;
561561
void setScale(int scale);
562562

563-
UCHAR* getBytes()
563+
UCHAR* getBytes() noexcept
564564
{
565565
return (UCHAR*)(v.table);
566566
}
567567

568-
static const unsigned BIAS = 128;
569-
static const unsigned PMAX = 39;
568+
static constexpr unsigned BIAS = 128;
569+
static constexpr unsigned PMAX = 39;
570570

571571
ULONG makeIndexKey(vary* buf, int scale);
572572

573-
static ULONG getIndexKeyLength()
573+
static ULONG getIndexKeyLength() noexcept
574574
{
575575
return 19;
576576
}
577577

578578
protected:
579579
ttmath::Int<TTMATH_BITS(128)> v;
580580

581-
static void overflow();
582-
static void zerodivide();
581+
[[noreturn]] static void overflow();
582+
[[noreturn]] static void zerodivide();
583583

584584
Int128 set(const char* value);
585585
};

0 commit comments

Comments
 (0)