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);
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)
@@ -135,17 +136,15 @@ void MetaName::test()
135
136
#endif
136
137
}
137
138
138
- const char * MetaName::EMPTY = " " ;
139
-
140
139
#if GROW_DEBUG > 1
141
- static const unsigned int hashSize[] = {1000 , 2000 , 4000 , 6000 , 8000 , 10000 ,
140
+ static constexpr unsigned int hashSize[] = {1000 , 2000 , 4000 , 6000 , 8000 , 10000 ,
142
141
12000 , 14000 , 16000 , 18000 , 20000 ,
143
142
22000 , 24000 , 26000 , 28000 , 30000 ,
144
143
32000 , 34000 , 36000 , 38000 , 40000 ,
145
144
42000 , 44000 , 46000 , 48000 , 50000 ,
146
145
52000 , 54000 , 56000 , 58000 , 60000 };
147
146
#else
148
- static const unsigned int hashSize[] = { 10007 , 100003 , 1000003 };
147
+ static constexpr unsigned int hashSize[] = { 10007 , 100003 , 1000003 };
149
148
#endif
150
149
151
150
Dictionary::Dictionary (MemoryPool& p)
@@ -187,7 +186,7 @@ Dictionary::HashTable::HashTable(MemoryPool& p, unsigned lvl)
187
186
table[n].store (nullptr , std::memory_order_relaxed);
188
187
}
189
188
190
- unsigned Dictionary::HashTable::getMaxLevel ()
189
+ unsigned Dictionary::HashTable::getMaxLevel () noexcept
191
190
{
192
191
return FB_NELEM (hashSize) - 1 ;
193
192
}
@@ -223,7 +222,7 @@ Dictionary::TableData* Dictionary::HashTable::getEntryByHash(const char* s, FB_S
223
222
return &table[h];
224
223
}
225
224
226
- bool Dictionary::checkConsistency (Dictionary::HashTable* oldValue)
225
+ bool Dictionary::checkConsistency (const Dictionary::HashTable* oldValue) noexcept
227
226
{
228
227
return oldValue->level == nextLevel.load ();
229
228
}
@@ -291,7 +290,7 @@ Dictionary::Word* Dictionary::get(const char* s, FB_SIZE_T len)
291
290
{
292
291
segment = FB_NEW_POOL (getPool ()) Segment;
293
292
++segCount;
294
- unsigned lvl = nextLevel.load ();
293
+ const unsigned lvl = nextLevel.load ();
295
294
if (lvl < HashTable::getMaxLevel () &&
296
295
segCount * Segment::getWordCapacity () > hashSize[lvl])
297
296
{
@@ -366,7 +365,7 @@ void Dictionary::growHash()
366
365
367
366
// move one level up size of hash table
368
367
HashTable* tab = hashTable.load ();
369
- unsigned lvl = ++nextLevel;
368
+ const unsigned lvl = ++nextLevel;
370
369
fb_assert (lvl == tab->level + 1 );
371
370
fb_assert (lvl <= HashTable::getMaxLevel ());
372
371
@@ -421,7 +420,7 @@ Dictionary::HashTable* Dictionary::waitForMutex(Jrd::Dictionary::Word** checkWor
421
420
return t;
422
421
423
422
// may be we already have that word in new table
424
- FB_SIZE_T len = (*checkWordPtr)->length ();
423
+ const FB_SIZE_T len = (*checkWordPtr)->length ();
425
424
const char * s = (*checkWordPtr)->c_str ();
426
425
Word* word = t->getEntryByHash (s, len)->load ();
427
426
while (word)
@@ -441,25 +440,25 @@ Dictionary::HashTable* Dictionary::waitForMutex(Jrd::Dictionary::Word** checkWor
441
440
return t;
442
441
}
443
442
444
- Dictionary::Segment::Segment ()
443
+ Dictionary::Segment::Segment () noexcept
445
444
{
446
445
position.store (0 , std::memory_order_relaxed);
447
446
}
448
447
449
- unsigned Dictionary::Segment::getWordCapacity ()
448
+ constexpr unsigned Dictionary::Segment::getWordCapacity () noexcept
450
449
{
451
- const unsigned AVERAGE_BYTES_LEN = 16 ;
450
+ constexpr unsigned AVERAGE_BYTES_LEN = 16 ;
452
451
return SEG_BUFFER_SIZE / getWordLength (AVERAGE_BYTES_LEN);
453
452
}
454
453
455
- unsigned Dictionary::Segment::getWordLength (FB_SIZE_T len)
454
+ constexpr unsigned Dictionary::Segment::getWordLength (FB_SIZE_T len) noexcept
456
455
{
457
456
// calculate length in sizeof(Word*)
458
457
len += 2 ;
459
- return 1 + (len / sizeof (Word*)) + (len % sizeof (Word*) ? 1 : 0 );
458
+ return 1 + (len / sizeof (Word*)) + (( len % sizeof (Word*) ) ? 1 : 0 );
460
459
}
461
460
462
- Dictionary::Word* Dictionary::Segment::getSpace (FB_SIZE_T len DIC_STAT_SEGMENT_PAR)
461
+ Dictionary::Word* Dictionary::Segment::getSpace (FB_SIZE_T len DIC_STAT_SEGMENT_PAR) noexcept
463
462
{
464
463
len = getWordLength (len);
465
464
@@ -470,7 +469,7 @@ Dictionary::Word* Dictionary::Segment::getSpace(FB_SIZE_T len DIC_STAT_SEGMENT_P
470
469
for (;;)
471
470
{
472
471
// calculate and check new position
473
- unsigned newPos = oldPos + len;
472
+ const unsigned newPos = oldPos + len;
474
473
if (newPos >= SEG_BUFFER_SIZE)
475
474
break ;
476
475
0 commit comments