Skip to content

Commit d22232e

Browse files
committed
constexpr+noexcept dba
1 parent 3a5bc3a commit d22232e

File tree

1 file changed

+40
-55
lines changed

1 file changed

+40
-55
lines changed

src/utilities/gstat/dba.epp

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ DATABASE DB = STATIC "yachts.lnk";
9292
#define DB db_handle
9393
#define isc_status status_vector
9494

95-
const SSHORT BUCKETS = 5;
95+
constexpr SSHORT BUCKETS = 5;
9696
//#define WINDOW_SIZE (1 << 17)
9797

9898
struct dba_idx
@@ -130,7 +130,7 @@ struct dba_blob_statistics
130130
FB_UINT64 blob_space = 0;
131131
FB_UINT64 blob_pages = 0;
132132

133-
dba_blob_statistics& operator+=(const dba_blob_statistics& rhs)
133+
dba_blob_statistics& operator+=(const dba_blob_statistics& rhs) noexcept
134134
{
135135
blob_count += rhs.blob_count;
136136
blob_space += rhs.blob_space;
@@ -202,9 +202,9 @@ static void analyze_index(const dba_rel*, dba_idx*);
202202
static ULONG lastUsedPage(ULONG);
203203

204204
#if (defined WIN_NT)
205-
static void db_error(SLONG);
205+
[[noreturn]] static void db_error(SLONG);
206206
#else
207-
static void db_error(int);
207+
[[noreturn]] static void db_error(int);
208208
#endif
209209

210210
static USHORT get_format_length(ISC_STATUS*, isc_db_handle, isc_tr_handle, ISC_QUAD&);
@@ -216,7 +216,7 @@ static void db_close(void* file_desc);
216216
#else
217217
static void db_close(int);
218218
#endif
219-
static void dba_error(USHORT, const SafeArg& arg = SafeArg());
219+
[[noreturn]] static void dba_error(USHORT, const SafeArg& arg = SafeArg());
220220
static void dba_print(bool, USHORT, const SafeArg& arg = SafeArg());
221221
static void print_distribution(const SCHAR*, const ULONG*);
222222
static void print_help();
@@ -239,45 +239,30 @@ struct dba_mem
239239

240240
// threading declarations for thread data
241241

242-
class tdba : public ThreadData
242+
class tdba final : public ThreadData
243243
{
244244
public:
245245
explicit tdba(Firebird::UtilSvc* us)
246246
: ThreadData(tddDBA), uSvc(us)
247247
{
248-
//dba_throw = false;
249-
file = nullptr;
250-
relations = nullptr;
251-
schemas = nullptr;
252-
page_size = 0;
253-
dp_per_pp = 0;
254-
max_records = 0;
255-
page_number = 0;
256-
buffer1 = nullptr;
257-
buffer2 = nullptr;
258-
global_buffer = nullptr;
259-
exit_code = 0;
260-
head_of_mem_list = nullptr;
261-
memset(dba_status_vector, 0, sizeof (dba_status_vector));
262248
dba_status = dba_status_vector;
263249
}
264250

265-
//bool dba_throw;
266251
Firebird::UtilSvc* uSvc;
267-
dba_fil* file;
268-
dba_rel* relations;
269-
dba_schema* schemas;
270-
USHORT page_size;
271-
USHORT dp_per_pp;
272-
USHORT max_records;
273-
ULONG page_number;
274-
pag* buffer1;
275-
pag* buffer2;
276-
pag* global_buffer;
277-
int exit_code;
278-
dba_mem *head_of_mem_list;
252+
dba_fil* file = nullptr;
253+
dba_rel* relations = nullptr;
254+
dba_schema* schemas = nullptr;
255+
USHORT page_size = 0;
256+
USHORT dp_per_pp = 0;
257+
USHORT max_records = 0;
258+
ULONG page_number = 0;
259+
pag* buffer1 = nullptr;
260+
pag* buffer2 = nullptr;
261+
pag* global_buffer = nullptr;
262+
int exit_code = 0;
263+
dba_mem *head_of_mem_list = nullptr;
279264
ISC_STATUS *dba_status;
280-
ISC_STATUS_ARRAY dba_status_vector;
265+
ISC_STATUS_ARRAY dba_status_vector{};
281266

282267
static inline tdba* getSpecific()
283268
{
@@ -295,7 +280,7 @@ public:
295280
};
296281

297282

298-
void inline dba_exit(int code, tdba* tddba)
283+
[[noreturn]] void inline dba_exit(int code, tdba* tddba)
299284
{
300285
tddba->exit_code = code;
301286
// Throw this kind of exception, because gstat uses status vector (and stuffException) to
@@ -310,7 +295,7 @@ namespace
310295

311296
bool shutdownRequested = false;
312297

313-
int gstatShutdown(const int reason, const int, void*)
298+
int gstatShutdown(const int reason, const int, void*) noexcept
314299
{
315300
if (reason == fb_shutrsn_signal)
316301
{
@@ -328,7 +313,7 @@ namespace
328313
}
329314
}
330315

331-
void getDateTime(char* datetime, FB_SIZE_T sizeof_datetime)
316+
void getDateTime(char* datetime, FB_SIZE_T sizeof_datetime) noexcept
332317
{
333318
time_t t;
334319
time(&t);
@@ -342,7 +327,7 @@ namespace
342327
}
343328
} // namespace
344329

345-
const USHORT GSTAT_MSG_FAC = 21;
330+
constexpr USHORT GSTAT_MSG_FAC = FB_IMPL_MSG_FACILITY_GSTAT;
346331

347332

348333
int main_gstat(Firebird::UtilSvc* uSvc)
@@ -651,7 +636,7 @@ int gstat(Firebird::UtilSvc* uSvc)
651636
expandDatabaseName(fileName, tempStr, NULL);
652637
fileName = tempStr;
653638

654-
dba_fil* file = db_open(fileName.c_str(), fileName.length());
639+
const dba_fil* file = db_open(fileName.c_str(), fileName.length());
655640

656641
alignas(DIRECT_IO_BLOCK_SIZE) SCHAR temp[MAX(RAW_HEADER_SIZE, DIRECT_IO_BLOCK_SIZE)];
657642
tddba->page_size = MAX(RAW_HEADER_SIZE, DIRECT_IO_BLOCK_SIZE);
@@ -704,25 +689,25 @@ int gstat(Firebird::UtilSvc* uSvc)
704689
class Statist
705690
{
706691
public:
707-
Statist()
692+
Statist() noexcept
708693
: enc(0), non(0)
709694
{ }
710695

711-
void print(USHORT messageNo)
696+
void print(USHORT messageNo) const
712697
{
713698
dba_print(false, messageNo, SafeArg() << enc + non << enc << non);
714699
// msg 5[2-4]: <TYPE> pages: total @1, encrypted @2, non-crypted @3
715700
}
716701

717-
void log(UCHAR flags)
702+
void log(UCHAR flags) noexcept
718703
{
719704
if (flags & crypted_page)
720705
++enc;
721706
else
722707
++non;
723708
}
724709

725-
bool hasCrypted()
710+
bool hasCrypted() const noexcept
726711
{
727712
return enc > 0;
728713
}
@@ -733,7 +718,7 @@ int gstat(Firebird::UtilSvc* uSvc)
733718

734719
Statist data, index, blob, generator, other;
735720

736-
ULONG last = lastUsedPage(header->hdr_page_size);
721+
const ULONG last = lastUsedPage(header->hdr_page_size);
737722
for (page = 0; page <= last; ++page)
738723
{
739724
const pag* p = db_read(page, true);
@@ -782,7 +767,7 @@ int gstat(Firebird::UtilSvc* uSvc)
782767
dpb.insertTag(isc_dpb_no_garbage_collect);
783768

784769
const unsigned char* authBlock;
785-
unsigned int authBlockSize = uSvc->getAuthBlock(&authBlock);
770+
const unsigned int authBlockSize = uSvc->getAuthBlock(&authBlock);
786771
if (authBlockSize)
787772
{
788773
dpb.insertBytes(isc_dpb_auth_block, authBlock, authBlockSize);
@@ -1052,7 +1037,7 @@ int gstat(Firebird::UtilSvc* uSvc)
10521037

10531038
average = relation->rel_records ?
10541039
(double) relation->rel_format_space / relation->rel_records : 0.0;
1055-
double average2 = relation->rel_record_space ?
1040+
const double average2 = relation->rel_record_space ?
10561041
(double) relation->rel_format_space / relation->rel_record_space : 0.0;
10571042
uSvc->printf(false, " Average unpacked length: %.2f, compression ratio: %.2f\n",
10581043
average, average2);
@@ -1247,10 +1232,10 @@ int gstat(Firebird::UtilSvc* uSvc)
12471232

12481233
static ULONG lastUsedPage(ULONG pageSize)
12491234
{
1250-
const ULONG pipFirst = FIRST_PIP_PAGE;
1235+
constexpr ULONG pipFirst = FIRST_PIP_PAGE;
12511236
ULONG pipLast = pipFirst;
1252-
ULONG pagesPerPIP = Ods::pagesPerPIP(pageSize);
1253-
ULONG bytesBitPIP = Ods::bytesBitPIP(pageSize);
1237+
const ULONG pagesPerPIP = Ods::pagesPerPIP(pageSize);
1238+
const ULONG bytesBitPIP = Ods::bytesBitPIP(pageSize);
12541239
page_inv_page* pip;
12551240

12561241
while (true)
@@ -1267,7 +1252,7 @@ static ULONG lastUsedPage(ULONG pageSize)
12671252
if (pip->pip_used != pagesPerPIP)
12681253
break;
12691254

1270-
UCHAR lastByte = pip->pip_bits[bytesBitPIP - 1];
1255+
const UCHAR lastByte = pip->pip_bits[bytesBitPIP - 1];
12711256
if (lastByte & 0x80)
12721257
break;
12731258

@@ -1577,7 +1562,7 @@ static void analyze_index( const dba_rel* relation, dba_idx* index)
15771562
* Functional description
15781563
*
15791564
**************************************/
1580-
tdba* tddba = tdba::getSpecific();
1565+
const tdba* tddba = tdba::getSpecific();
15811566

15821567
const index_root_page* index_root = (const index_root_page*) db_read(relation->rel_index_root);
15831568

@@ -1816,7 +1801,7 @@ static void db_close(void* file_desc)
18161801
CloseHandle(file_desc);
18171802
}
18181803

1819-
static void db_error( SLONG status)
1804+
[[noreturn]] static void db_error( SLONG status)
18201805
{
18211806
/**************************************
18221807
*
@@ -1927,7 +1912,7 @@ static const pag* db_read( ULONG page_number, bool ok_enc)
19271912
if (SetFilePointer(tddba->file->fil_desc, (LONG) liOffset.LowPart, &liOffset.HighPart, FILE_BEGIN) ==
19281913
(DWORD) -1)
19291914
{
1930-
int lastError = GetLastError();
1915+
const int lastError = GetLastError();
19311916
if (lastError != NO_ERROR)
19321917
{
19331918
tddba->uSvc->getStatusAccessor().setServiceStatus(GSTAT_MSG_FAC, 30, SafeArg());
@@ -1983,7 +1968,7 @@ static void db_close( int file_desc)
19831968
close(file_desc);
19841969
}
19851970

1986-
static void db_error( int status)
1971+
[[noreturn]] static void db_error( int status)
19871972
{
19881973
/**************************************
19891974
*
@@ -2103,7 +2088,7 @@ static const pag* db_read( ULONG page_number, bool ok_enc)
21032088
#endif
21042089

21052090

2106-
static void dba_error(USHORT errcode, const SafeArg& arg)
2091+
[[noreturn]] static void dba_error(USHORT errcode, const SafeArg& arg)
21072092
{
21082093
/**************************************
21092094
*

0 commit comments

Comments
 (0)