Skip to content

Commit 4fff97a

Browse files
committed
constexpr in pag
1 parent f1253ff commit 4fff97a

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

src/jrd/pag.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ using namespace Firebird;
101101

102102
namespace
103103
{
104-
const char* const SCRATCH = "fb_table_";
105-
const int MIN_EXTEND_BYTES = 128 * 1024; // 128KB
104+
constexpr const char* const SCRATCH = "fb_table_";
105+
constexpr int MIN_EXTEND_BYTES = 128 * 1024; // 128KB
106106

107107
inline void ensureDbWritable(thread_db* tdbb)
108108
{
109-
const auto dbb = tdbb->getDatabase();
109+
const auto* dbb = tdbb->getDatabase();
110110

111111
if (dbb->readOnly())
112112
ERR_post(Arg::Gds(isc_read_only_database));
@@ -115,11 +115,11 @@ namespace
115115
class HeaderClumplet
116116
{
117117
public:
118-
HeaderClumplet(header_page* header, USHORT type)
118+
HeaderClumplet(header_page* header, USHORT type) noexcept
119119
: m_header(header), m_type(type)
120120
{}
121121

122-
UCHAR* find(const UCHAR** clump_end = nullptr) const
122+
UCHAR* find(const UCHAR** clump_end = nullptr) const noexcept
123123
{
124124
UCHAR* p = m_header->hdr_data;
125125
UCHAR* q = nullptr;
@@ -136,7 +136,7 @@ namespace
136136
return q;
137137
}
138138

139-
bool checkSpace(USHORT length) const
139+
bool checkSpace(USHORT length) const noexcept
140140
{
141141
const auto freeSpace = m_header->hdr_page_size - m_header->hdr_end;
142142
if (freeSpace > 2 + length)
@@ -268,8 +268,8 @@ namespace
268268

269269
ULONG ensureDiskSpace(thread_db* tdbb, WIN* pip_window, const PageNumber pageNum, ULONG pipUsed)
270270
{
271-
const auto dbb = tdbb->getDatabase();
272-
PageManager& pageMgr = dbb->dbb_page_manager;
271+
const auto* dbb = tdbb->getDatabase();
272+
const PageManager& pageMgr = dbb->dbb_page_manager;
273273
PageSpace* const pageSpace = pageMgr.findPageSpace(pageNum.getPageSpaceID());
274274

275275
ULONG newUsed = pipUsed;
@@ -449,9 +449,9 @@ PAG PAG_allocate_pages(thread_db* tdbb, WIN* window, unsigned cntAlloc, bool ali
449449
*
450450
**************************************/
451451
SET_TDBB(tdbb);
452-
const auto dbb = tdbb->getDatabase();
452+
const auto* dbb = tdbb->getDatabase();
453453

454-
PageManager& pageMgr = dbb->dbb_page_manager;
454+
const PageManager& pageMgr = dbb->dbb_page_manager;
455455
PageSpace* const pageSpace = pageMgr.findPageSpace(window->win_page.getPageSpaceID());
456456
fb_assert(pageSpace);
457457

@@ -838,7 +838,7 @@ void PAG_format_pip(thread_db* tdbb, PageSpace& pageSpace)
838838
*
839839
**************************************/
840840
SET_TDBB(tdbb);
841-
const auto dbb = tdbb->getDatabase();
841+
const auto* dbb = tdbb->getDatabase();
842842

843843
// Initialize first SCN's Page
844844
pageSpace.scnFirst = 0;
@@ -865,7 +865,7 @@ void PAG_format_pip(thread_db* tdbb, PageSpace& pageSpace)
865865
pages->pip_header.pag_type = pag_pages;
866866
pages->pip_used = (pageSpace.scnFirst ? pageSpace.scnFirst : pageSpace.pipFirst) + 1;
867867
pages->pip_min = pages->pip_used;
868-
int count = dbb->dbb_page_size - static_cast<int>(offsetof(page_inv_page, pip_bits[0]));
868+
const int count = dbb->dbb_page_size - static_cast<int>(offsetof(page_inv_page, pip_bits[0]));
869869

870870
memset(pages->pip_bits, 0xFF, count);
871871

@@ -943,7 +943,7 @@ void PAG_header(thread_db* tdbb, bool info, const TriState newForceWrite)
943943
SET_TDBB(tdbb);
944944
Database* const dbb = tdbb->getDatabase();
945945

946-
const auto attachment = tdbb->getAttachment();
946+
const auto* attachment = tdbb->getAttachment();
947947
fb_assert(attachment);
948948

949949
WIN window(HEADER_PAGE_NUMBER);
@@ -1097,7 +1097,7 @@ void PAG_header_init(thread_db* tdbb)
10971097
SET_TDBB(tdbb);
10981098
const auto dbb = tdbb->getDatabase();
10991099

1100-
const auto attachment = tdbb->getAttachment();
1100+
const auto* attachment = tdbb->getAttachment();
11011101
fb_assert(attachment);
11021102

11031103
// Allocate a spare buffer which is large enough,
@@ -1118,7 +1118,7 @@ void PAG_header_init(thread_db* tdbb)
11181118
if (!PIO_header(tdbb, temp_page, headerSize))
11191119
ERR_post(Arg::Gds(isc_bad_db_format) << Arg::Str(attachment->att_filename));
11201120

1121-
const auto header = (header_page*) temp_page;
1121+
const auto* header = (header_page*) temp_page;
11221122

11231123
if (header->hdr_header.pag_type != pag_header || header->hdr_header.pag_pageno != HEADER_PAGE)
11241124
ERR_post(Arg::Gds(isc_bad_db_format) << Arg::Str(attachment->att_filename));
@@ -1226,7 +1226,7 @@ void PAG_init2(thread_db* tdbb)
12261226
const auto dbb = tdbb->getDatabase();
12271227

12281228
WIN window(HEADER_PAGE_NUMBER);
1229-
const auto header = (header_page*) CCH_FETCH(tdbb, &window, LCK_read, pag_header);
1229+
const auto* header = (header_page*) CCH_FETCH(tdbb, &window, LCK_read, pag_header);
12301230

12311231
for (const UCHAR* p = header->hdr_data; *p != HDR_end; p += 2 + p[1])
12321232
{
@@ -1265,7 +1265,7 @@ SLONG PAG_last_page(thread_db* tdbb)
12651265
*
12661266
**************************************/
12671267
SET_TDBB(tdbb);
1268-
const auto dbb = tdbb->getDatabase();
1268+
const auto* dbb = tdbb->getDatabase();
12691269

12701270
return PageSpace::lastUsedPage(dbb);
12711271
}
@@ -1306,9 +1306,9 @@ void PAG_release_pages(thread_db* tdbb, USHORT pageSpaceID, int cntRelease,
13061306
*
13071307
**************************************/
13081308
SET_TDBB(tdbb);
1309-
const auto dbb = tdbb->getDatabase();
1309+
const auto* dbb = tdbb->getDatabase();
13101310

1311-
PageManager& pageMgr = dbb->dbb_page_manager;
1311+
const PageManager& pageMgr = dbb->dbb_page_manager;
13121312
PageSpace* const pageSpace = pageMgr.findPageSpace(pageSpaceID);
13131313
fb_assert(pageSpace);
13141314

@@ -1521,7 +1521,7 @@ void PAG_set_db_readonly(thread_db* tdbb, bool flag)
15211521
// Take into account current attachment ID, else next attachment
15221522
// (cache writer, for examle) will get the same att ID and wait
15231523
// for att lock indefinitely.
1524-
Attachment* att = tdbb->getAttachment();
1524+
const Attachment* att = tdbb->getAttachment();
15251525
if (att->att_attachment_id)
15261526
header->hdr_attachment_id = att->att_attachment_id;
15271527

@@ -1756,7 +1756,7 @@ ULONG PageSpace::maxAlloc(const Database* dbb)
17561756
return pgSpace->maxAlloc();
17571757
}
17581758

1759-
bool PageSpace::onRawDevice() const
1759+
bool PageSpace::onRawDevice() const noexcept
17601760
{
17611761
return (file->fil_flags & FIL_raw_device) != 0;
17621762
}
@@ -1782,18 +1782,18 @@ ULONG PageSpace::lastUsedPage()
17821782

17831783
while (true)
17841784
{
1785-
pag* page = CCH_FETCH(tdbb, &window, LCK_read, pag_undefined);
1785+
const pag* page = CCH_FETCH(tdbb, &window, LCK_read, pag_undefined);
17861786

17871787
if (moveUp)
17881788
{
17891789
fb_assert(page->pag_type == pag_pages);
17901790

1791-
page_inv_page* pip = (page_inv_page*) page;
1791+
const page_inv_page* pip = (page_inv_page*) page;
17921792

17931793
if (pip->pip_used != pageMgr.pagesPerPIP)
17941794
break;
17951795

1796-
UCHAR lastByte = pip->pip_bits[pageMgr.bytesBitPIP - 1];
1796+
const UCHAR lastByte = pip->pip_bits[pageMgr.bytesBitPIP - 1];
17971797
if (lastByte & 0x80)
17981798
break;
17991799
}
@@ -1822,7 +1822,7 @@ ULONG PageSpace::lastUsedPage()
18221822
window.win_page = pipLast;
18231823
}
18241824

1825-
page_inv_page* pip = (page_inv_page*) window.win_buffer;
1825+
const page_inv_page* pip = (page_inv_page*) window.win_buffer;
18261826

18271827
int last_bit = pip->pip_used;
18281828
int byte_num = last_bit / 8;
@@ -1903,7 +1903,7 @@ ULONG PageSpace::usedPages()
19031903

19041904
while (true)
19051905
{
1906-
page_inv_page* pip = (page_inv_page*) CCH_FETCH(tdbb, &window, LCK_read, pag_undefined);
1906+
const page_inv_page* pip = (page_inv_page*) CCH_FETCH(tdbb, &window, LCK_read, pag_undefined);
19071907
if (pip->pip_header.pag_type != pag_pages)
19081908
{
19091909
CCH_RELEASE(tdbb, &window);
@@ -2006,7 +2006,7 @@ bool PageSpace::extend(thread_db* tdbb, const ULONG pageNum, const bool forceSiz
20062006
return true;
20072007
}
20082008

2009-
ULONG PageSpace::getSCNPageNum(ULONG sequence)
2009+
ULONG PageSpace::getSCNPageNum(ULONG sequence) noexcept
20102010
{
20112011
/**************************************
20122012
*
@@ -2076,7 +2076,7 @@ void PageManager::closeAll()
20762076
void PageManager::initTempPageSpace(thread_db* tdbb)
20772077
{
20782078
SET_TDBB(tdbb);
2079-
Database* const dbb = tdbb->getDatabase();
2079+
const Database* dbb = tdbb->getDatabase();
20802080

20812081
fb_assert(tempPageSpaceID == 0);
20822082

@@ -2199,10 +2199,10 @@ ULONG PAG_page_count(thread_db* tdbb)
21992199

22002200
void PAG_set_page_scn(thread_db* tdbb, win* window)
22012201
{
2202-
Database* dbb = tdbb->getDatabase();
2202+
const Database* dbb = tdbb->getDatabase();
22032203
fb_assert(dbb->dbb_ods_version >= ODS_VERSION12);
22042204

2205-
PageManager& pageMgr = dbb->dbb_page_manager;
2205+
const PageManager& pageMgr = dbb->dbb_page_manager;
22062206
PageSpace* const pageSpace = pageMgr.findPageSpace(window->win_page.getPageSpaceID());
22072207

22082208
if (pageSpace->isTemporary())

src/jrd/pag.h

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ class PageControl : public pool_alloc<type_pgc>
6060
// TEMP_PAGE_SPACE and page spaces above TEMP_PAGE_SPACE contain temporary pages
6161
// TRANS_PAGE_SPACE is pseudo space to store transaction numbers in precedence stack
6262
// INVALID_PAGE_SPACE is to ???
63-
const USHORT INVALID_PAGE_SPACE = 0;
64-
const USHORT DB_PAGE_SPACE = 1;
65-
const USHORT TRANS_PAGE_SPACE = 255;
66-
const USHORT TEMP_PAGE_SPACE = 256;
63+
inline constexpr USHORT INVALID_PAGE_SPACE = 0;
64+
inline constexpr USHORT DB_PAGE_SPACE = 1;
65+
inline constexpr USHORT TRANS_PAGE_SPACE = 255;
66+
inline constexpr USHORT TEMP_PAGE_SPACE = 256;
6767

68-
const USHORT PAGES_IN_EXTENT = 8;
68+
inline constexpr USHORT PAGES_IN_EXTENT = 8;
6969

7070
class jrd_file;
7171
class Database;
@@ -98,17 +98,17 @@ class PageSpace : public pool_alloc<type_PageSpace>
9898

9999
jrd_file* file;
100100

101-
static inline bool isTemporary(USHORT aPageSpaceID)
101+
static inline bool isTemporary(USHORT aPageSpaceID) noexcept
102102
{
103103
return (aPageSpaceID >= TEMP_PAGE_SPACE);
104104
}
105105

106-
inline bool isTemporary() const
106+
inline bool isTemporary() const noexcept
107107
{
108108
return isTemporary(pageSpaceID);
109109
}
110110

111-
static inline SLONG generate(const PageSpace* Item)
111+
static inline SLONG generate(const PageSpace* Item) noexcept
112112
{
113113
return Item->pageSpaceID;
114114
}
@@ -133,11 +133,11 @@ class PageSpace : public pool_alloc<type_PageSpace>
133133
bool extend(thread_db*, const ULONG, const bool);
134134

135135
// get SCN's page number
136-
ULONG getSCNPageNum(ULONG sequence);
136+
ULONG getSCNPageNum(ULONG sequence) noexcept;
137137
static ULONG getSCNPageNum(const Database* dbb, ULONG sequence);
138138

139139
// is pagespace on raw device
140-
bool onRawDevice() const;
140+
bool onRawDevice() const noexcept;
141141

142142
private:
143143
ULONG maxPageNumber;
@@ -202,48 +202,48 @@ class PageNumber
202202
{
203203
public:
204204
// CVC: To be completely in sync, the second param would have to be TraNumber
205-
inline PageNumber(const USHORT aPageSpace, const ULONG aPageNum)
205+
inline PageNumber(const USHORT aPageSpace, const ULONG aPageNum) noexcept
206206
: pageNum(aPageNum), pageSpaceID(aPageSpace)
207207
{
208208
// Some asserts are commented cause 0 was also used as 'does not matter' pagespace
209209
// fb_assert(pageSpaceID != INVALID_PAGE_SPACE);
210210
}
211211

212212
// Required to be able to keep it in Firebird::Stack
213-
inline PageNumber()
213+
inline PageNumber() noexcept
214214
: pageNum(0), pageSpaceID(INVALID_PAGE_SPACE)
215215
{ }
216216

217-
inline PageNumber(const PageNumber& from)
217+
inline PageNumber(const PageNumber& from) noexcept
218218
: pageNum(from.pageNum), pageSpaceID(from.pageSpaceID)
219219
{ }
220220

221-
inline ULONG getPageNum() const
221+
inline ULONG getPageNum() const noexcept
222222
{
223223
// fb_assert(pageSpaceID != INVALID_PAGE_SPACE);
224224
return pageNum;
225225
}
226226

227-
inline USHORT getPageSpaceID() const
227+
inline USHORT getPageSpaceID() const noexcept
228228
{
229229
fb_assert(pageSpaceID != INVALID_PAGE_SPACE);
230230
return pageSpaceID;
231231
}
232232

233-
inline USHORT setPageSpaceID(const USHORT aPageSpaceID)
233+
inline USHORT setPageSpaceID(const USHORT aPageSpaceID) noexcept
234234
{
235235
fb_assert(aPageSpaceID != INVALID_PAGE_SPACE);
236236
pageSpaceID = aPageSpaceID;
237237
return pageSpaceID;
238238
}
239239

240-
inline bool isTemporary() const
240+
inline bool isTemporary() const noexcept
241241
{
242242
fb_assert(pageSpaceID != INVALID_PAGE_SPACE);
243243
return PageSpace::isTemporary(pageSpaceID);
244244
}
245245

246-
inline static USHORT getLockLen()
246+
static inline constexpr USHORT getLockLen() noexcept
247247
{
248248
return 2 * sizeof(ULONG);
249249
}
@@ -259,53 +259,53 @@ class PageNumber
259259
memcpy(str, &val, sizeof(ULONG));
260260
}
261261

262-
inline PageNumber& operator=(const PageNumber& from)
262+
inline PageNumber& operator=(const PageNumber& from) noexcept
263263
{
264264
pageSpaceID = from.pageSpaceID;
265265
// fb_assert(pageSpaceID != INVALID_PAGE_SPACE);
266266
pageNum = from.pageNum;
267267
return *this;
268268
}
269269

270-
inline ULONG operator=(const ULONG from)
270+
inline ULONG operator=(const ULONG from) noexcept
271271
{
272272
// fb_assert(pageSpaceID != INVALID_PAGE_SPACE);
273273
pageNum = from;
274274
return pageNum;
275275
}
276276

277-
inline bool operator==(const PageNumber& other) const
277+
inline bool operator==(const PageNumber& other) const noexcept
278278
{
279279
return (pageNum == other.pageNum) && (pageSpaceID == other.pageSpaceID);
280280
}
281281

282-
inline bool operator!=(const PageNumber& other) const
282+
inline bool operator!=(const PageNumber& other) const noexcept
283283
{
284284
return !(*this == other);
285285
}
286286

287-
inline bool operator>(const PageNumber& other) const
287+
inline bool operator>(const PageNumber& other) const noexcept
288288
{
289289
fb_assert(pageSpaceID != INVALID_PAGE_SPACE);
290290
fb_assert(other.pageSpaceID != INVALID_PAGE_SPACE);
291291
return (pageSpaceID > other.pageSpaceID) ||
292292
((pageSpaceID == other.pageSpaceID) && (pageNum > other.pageNum));
293293
}
294294

295-
inline bool operator>=(const PageNumber& other) const
295+
inline bool operator>=(const PageNumber& other) const noexcept
296296
{
297297
fb_assert(pageSpaceID != INVALID_PAGE_SPACE);
298298
fb_assert(other.pageSpaceID != INVALID_PAGE_SPACE);
299299
return (pageSpaceID > other.pageSpaceID) ||
300300
((pageSpaceID == other.pageSpaceID) && (pageNum >= other.pageNum));
301301
}
302302

303-
inline bool operator<(const PageNumber& other) const
303+
inline bool operator<(const PageNumber& other) const noexcept
304304
{
305305
return !(*this >= other);
306306
}
307307

308-
inline bool operator<=(const PageNumber& other) const
308+
inline bool operator<=(const PageNumber& other) const noexcept
309309
{
310310
return !(*this > other);
311311
}

0 commit comments

Comments
 (0)