29
29
#include " firebird.h"
30
30
31
31
#include < stdarg.h>
32
+ #include < algorithm>
32
33
33
34
#include " ../jrd/MetaName.h"
34
35
#include " ../common/classes/MetaString.h"
@@ -42,7 +43,7 @@ int MetaName::compare(const char* s, FB_SIZE_T len) const
42
43
if (s)
43
44
{
44
45
adjustLength (s, len);
45
- FB_SIZE_T x = length () < len ? length () : len;
46
+ const FB_SIZE_T x = std::min ( length (), len) ;
46
47
int rc = memcmp (c_str (), s, x);
47
48
if (rc)
48
49
{
@@ -55,11 +56,11 @@ int MetaName::compare(const char* s, FB_SIZE_T len) const
55
56
return length () - len;
56
57
}
57
58
58
- void MetaName::adjustLength (const char * const s, FB_SIZE_T& len)
59
+ void MetaName::adjustLength (const char * const s, FB_SIZE_T& len) noexcept
59
60
{
61
+ fb_assert (s || len == 0 );
60
62
if (len > MAX_SQL_IDENTIFIER_LEN)
61
63
{
62
- fb_assert (s);
63
64
#ifdef DEV_BUILD
64
65
for (FB_SIZE_T i = MAX_SQL_IDENTIFIER_LEN; i < len; ++i)
65
66
fb_assert (s[i] == ' \0 ' || s[i] == ' ' );
@@ -81,7 +82,7 @@ void MetaName::printf(const char* format, ...)
81
82
char data[MAX_SQL_IDENTIFIER_LEN + 1 ];
82
83
va_list params;
83
84
va_start (params, format);
84
- int len = VSNPRINTF (data, MAX_SQL_IDENTIFIER_LEN, format, params);
85
+ int len = vsnprintf (data, MAX_SQL_IDENTIFIER_LEN, format, params);
85
86
va_end (params);
86
87
87
88
if (len < 0 || FB_SIZE_T (len) > MAX_SQL_IDENTIFIER_LEN)
@@ -105,7 +106,7 @@ FB_SIZE_T MetaName::copyTo(char* to, FB_SIZE_T toSize) const
105
106
return toSize;
106
107
}
107
108
108
- MetaName::operator Firebird::MetaString () const
109
+ MetaName::operator Firebird::MetaString () const noexcept
109
110
{
110
111
return Firebird::MetaString (c_str (), length ());
111
112
}
@@ -125,7 +126,7 @@ void MetaName::test()
125
126
#if defined(DEV_BUILD) || GROW_DEBUG > 0
126
127
if (word)
127
128
{
128
- Dictionary::Word* checkWord = get (word->c_str (), word->length ());
129
+ const Dictionary::Word* checkWord = get (word->c_str (), word->length ());
129
130
fb_assert (checkWord == word);
130
131
#ifndef DEV_BUILD
131
132
if (word != checkWord)
@@ -138,14 +139,14 @@ void MetaName::test()
138
139
const char * MetaName::EMPTY = " " ;
139
140
140
141
#if GROW_DEBUG > 1
141
- static const unsigned int hashSize[] = {1000 , 2000 , 4000 , 6000 , 8000 , 10000 ,
142
+ static constexpr unsigned int hashSize[] = {1000 , 2000 , 4000 , 6000 , 8000 , 10000 ,
142
143
12000 , 14000 , 16000 , 18000 , 20000 ,
143
144
22000 , 24000 , 26000 , 28000 , 30000 ,
144
145
32000 , 34000 , 36000 , 38000 , 40000 ,
145
146
42000 , 44000 , 46000 , 48000 , 50000 ,
146
147
52000 , 54000 , 56000 , 58000 , 60000 };
147
148
#else
148
- static const unsigned int hashSize[] = { 10007 , 100003 , 1000003 };
149
+ static constexpr unsigned int hashSize[] = { 10007 , 100003 , 1000003 };
149
150
#endif
150
151
151
152
Dictionary::Dictionary (MemoryPool& p)
@@ -187,7 +188,7 @@ Dictionary::HashTable::HashTable(MemoryPool& p, unsigned lvl)
187
188
table[n].store (nullptr , std::memory_order_relaxed);
188
189
}
189
190
190
- unsigned Dictionary::HashTable::getMaxLevel ()
191
+ unsigned Dictionary::HashTable::getMaxLevel () noexcept
191
192
{
192
193
return FB_NELEM (hashSize) - 1 ;
193
194
}
@@ -223,7 +224,7 @@ Dictionary::TableData* Dictionary::HashTable::getEntryByHash(const char* s, FB_S
223
224
return &table[h];
224
225
}
225
226
226
- bool Dictionary::checkConsistency (Dictionary::HashTable* oldValue)
227
+ bool Dictionary::checkConsistency (const Dictionary::HashTable* oldValue) noexcept
227
228
{
228
229
return oldValue->level == nextLevel.load ();
229
230
}
@@ -291,7 +292,7 @@ Dictionary::Word* Dictionary::get(const char* s, FB_SIZE_T len)
291
292
{
292
293
segment = FB_NEW_POOL (getPool ()) Segment;
293
294
++segCount;
294
- unsigned lvl = nextLevel.load ();
295
+ const unsigned lvl = nextLevel.load ();
295
296
if (lvl < HashTable::getMaxLevel () &&
296
297
segCount * Segment::getWordCapacity () > hashSize[lvl])
297
298
{
@@ -366,7 +367,7 @@ void Dictionary::growHash()
366
367
367
368
// move one level up size of hash table
368
369
HashTable* tab = hashTable.load ();
369
- unsigned lvl = ++nextLevel;
370
+ const unsigned lvl = ++nextLevel;
370
371
fb_assert (lvl == tab->level + 1 );
371
372
fb_assert (lvl <= HashTable::getMaxLevel ());
372
373
@@ -421,7 +422,7 @@ Dictionary::HashTable* Dictionary::waitForMutex(Jrd::Dictionary::Word** checkWor
421
422
return t;
422
423
423
424
// may be we already have that word in new table
424
- FB_SIZE_T len = (*checkWordPtr)->length ();
425
+ const FB_SIZE_T len = (*checkWordPtr)->length ();
425
426
const char * s = (*checkWordPtr)->c_str ();
426
427
Word* word = t->getEntryByHash (s, len)->load ();
427
428
while (word)
@@ -441,25 +442,25 @@ Dictionary::HashTable* Dictionary::waitForMutex(Jrd::Dictionary::Word** checkWor
441
442
return t;
442
443
}
443
444
444
- Dictionary::Segment::Segment ()
445
+ Dictionary::Segment::Segment () noexcept
445
446
{
446
447
position.store (0 , std::memory_order_relaxed);
447
448
}
448
449
449
- unsigned Dictionary::Segment::getWordCapacity ()
450
+ unsigned constexpr Dictionary::Segment::getWordCapacity () noexcept
450
451
{
451
- const unsigned AVERAGE_BYTES_LEN = 16 ;
452
+ constexpr unsigned AVERAGE_BYTES_LEN = 16 ;
452
453
return SEG_BUFFER_SIZE / getWordLength (AVERAGE_BYTES_LEN);
453
454
}
454
455
455
- unsigned Dictionary::Segment::getWordLength (FB_SIZE_T len)
456
+ unsigned constexpr Dictionary::Segment::getWordLength (FB_SIZE_T len) noexcept
456
457
{
457
458
// calculate length in sizeof(Word*)
458
459
len += 2 ;
459
- return 1 + (len / sizeof (Word*)) + (len % sizeof (Word*) ? 1 : 0 );
460
+ return 1 + (len / sizeof (Word*)) + (( len % sizeof (Word*) ) ? 1 : 0 );
460
461
}
461
462
462
- Dictionary::Word* Dictionary::Segment::getSpace (FB_SIZE_T len DIC_STAT_SEGMENT_PAR)
463
+ Dictionary::Word* Dictionary::Segment::getSpace (FB_SIZE_T len DIC_STAT_SEGMENT_PAR) noexcept
463
464
{
464
465
len = getWordLength (len);
465
466
@@ -470,7 +471,7 @@ Dictionary::Word* Dictionary::Segment::getSpace(FB_SIZE_T len DIC_STAT_SEGMENT_P
470
471
for (;;)
471
472
{
472
473
// calculate and check new position
473
- unsigned newPos = oldPos + len;
474
+ const unsigned newPos = oldPos + len;
474
475
if (newPos >= SEG_BUFFER_SIZE)
475
476
break ;
476
477
0 commit comments