Skip to content

Commit 417ffde

Browse files
committed
noexcept in fb_string
1 parent 5b9ca7a commit 417ffde

File tree

2 files changed

+93
-91
lines changed

2 files changed

+93
-91
lines changed

src/common/classes/fb_string.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#else
4242
namespace
4343
{
44-
int StringIgnoreCaseCompare(const char* s1, const char* s2, unsigned int l)
44+
int StringIgnoreCaseCompare(const char* s1, const char* s2, unsigned int l) noexcept
4545
{
4646
while (l--)
4747
{
@@ -61,11 +61,10 @@ namespace {
6161
class strBitMask
6262
{
6363
private:
64-
char m[32];
64+
char m[32]{};
6565
public:
66-
strBitMask(Firebird::AbstractString::const_pointer s, Firebird::AbstractString::size_type l)
66+
strBitMask(Firebird::AbstractString::const_pointer s, Firebird::AbstractString::size_type l) noexcept
6767
{
68-
memset(m, 0, sizeof(m));
6968
if (l == Firebird::AbstractString::npos) {
7069
l = static_cast<Firebird::AbstractString::size_type>(strlen(s));
7170
}
@@ -76,7 +75,8 @@ namespace {
7675
m[uc >> 3] |= (1 << (uc & 7));
7776
}
7877
}
79-
inline bool Contains(const char c) const
78+
79+
inline bool Contains(const char c) const noexcept
8080
{
8181
const unsigned char uc = static_cast<unsigned char>(c);
8282
return m[uc >> 3] & (1 << (uc & 7));
@@ -203,9 +203,9 @@ namespace Firebird
203203
shrinkBuffer();
204204
}
205205

206-
AbstractString::size_type AbstractString::rfind(const_pointer s, const size_type pos) const
206+
AbstractString::size_type AbstractString::rfind(const_pointer s, const size_type pos) const noexcept
207207
{
208-
const size_type l = static_cast<size_type>(strlen(s));
208+
const size_type l = length(s);
209209
int lastpos = length() - l;
210210
if (lastpos < 0) {
211211
return npos;
@@ -223,7 +223,7 @@ namespace Firebird
223223
return npos;
224224
}
225225

226-
AbstractString::size_type AbstractString::rfind(char_type c, const size_type pos) const
226+
AbstractString::size_type AbstractString::rfind(char_type c, const size_type pos) const noexcept
227227
{
228228
int lastpos = length() - 1;
229229
if (lastpos < 0) {
@@ -242,7 +242,7 @@ namespace Firebird
242242
return npos;
243243
}
244244

245-
AbstractString::size_type AbstractString::find_first_of(const_pointer s, size_type pos, size_type n) const
245+
AbstractString::size_type AbstractString::find_first_of(const_pointer s, size_type pos, size_type n) const noexcept
246246
{
247247
const strBitMask sm(s, n);
248248
const_pointer p = &c_str()[pos];
@@ -256,7 +256,7 @@ namespace Firebird
256256
return npos;
257257
}
258258

259-
AbstractString::size_type AbstractString::find_last_of(const_pointer s, const size_type pos, size_type n) const
259+
AbstractString::size_type AbstractString::find_last_of(const_pointer s, const size_type pos, size_type n) const noexcept
260260
{
261261
const strBitMask sm(s, n);
262262
int lpos = length() - 1;
@@ -274,7 +274,7 @@ namespace Firebird
274274
return npos;
275275
}
276276

277-
AbstractString::size_type AbstractString::find_first_not_of(const_pointer s, size_type pos, size_type n) const
277+
AbstractString::size_type AbstractString::find_first_not_of(const_pointer s, size_type pos, size_type n) const noexcept
278278
{
279279
const strBitMask sm(s, n);
280280
const_pointer p = &c_str()[pos];
@@ -288,7 +288,7 @@ namespace Firebird
288288
return npos;
289289
}
290290

291-
AbstractString::size_type AbstractString::find_last_not_of(const_pointer s, const size_type pos, size_type n) const
291+
AbstractString::size_type AbstractString::find_last_not_of(const_pointer s, const size_type pos, size_type n) const noexcept
292292
{
293293
const strBitMask sm(s, n);
294294
int lpos = length() - 1;
@@ -357,16 +357,16 @@ extern "C" {
357357
#endif // WIN_NT
358358
}
359359

360-
void AbstractString::baseTrim(const TrimType whereTrim, const_pointer toTrim)
360+
void AbstractString::baseTrim(const TrimType whereTrim, const_pointer toTrim) noexcept
361361
{
362-
const strBitMask sm(toTrim, static_cast<size_type>(strlen(toTrim)));
362+
const strBitMask sm(toTrim, length(toTrim));
363363
const_pointer b = c_str();
364364
const_pointer e = c_str() + length() - 1;
365365
if (whereTrim != TrimRight)
366366
{
367367
while (b <= e)
368368
{
369-
if (! sm.Contains(*b)) {
369+
if (!sm.Contains(*b)) {
370370
break;
371371
}
372372
++b;
@@ -376,7 +376,7 @@ extern "C" {
376376
{
377377
while (b <= e)
378378
{
379-
if (! sm.Contains(*e)) {
379+
if (!sm.Contains(*e)) {
380380
break;
381381
}
382382
--e;
@@ -396,7 +396,7 @@ extern "C" {
396396
shrinkBuffer();
397397
}
398398

399-
bool AbstractString::baseMove(AbstractString&& rhs)
399+
bool AbstractString::baseMove(AbstractString&& rhs) noexcept
400400
{
401401
if (getPool() == rhs.getPool() && rhs.inlineBuffer != rhs.stringBuffer)
402402
{
@@ -476,7 +476,7 @@ extern "C" {
476476
}
477477
}
478478

479-
unsigned int AbstractString::hash(const_pointer string, const size_type tableSize)
479+
unsigned int AbstractString::hash(const_pointer string, const size_type tableSize) noexcept
480480
{
481481
unsigned int value = 0;
482482
unsigned char c;
@@ -490,18 +490,14 @@ extern "C" {
490490
return value % tableSize;
491491
}
492492

493-
bool AbstractString::equalsNoCase(AbstractString::const_pointer string) const
493+
bool AbstractString::equalsNoCase(AbstractString::const_pointer string) const noexcept
494494
{
495-
size_t l = strlen(string);
496-
if (l > length())
497-
{
498-
l = length();
499-
}
495+
size_t l = MIN(strlen(string), length());
500496
return (STRNCASECMP(c_str(), string, ++l) == 0);
501497
}
502498

503499
int PathNameComparator::compare(AbstractString::const_pointer s1, AbstractString::const_pointer s2,
504-
const AbstractString::size_type n)
500+
const AbstractString::size_type n) noexcept
505501
{
506502
if (CASE_SENSITIVITY)
507503
return memcmp(s1, s2, n);
@@ -510,7 +506,7 @@ extern "C" {
510506
}
511507

512508
int IgnoreCaseComparator::compare(AbstractString::const_pointer s1, AbstractString::const_pointer s2,
513-
const AbstractString::size_type n)
509+
const AbstractString::size_type n) noexcept
514510
{
515511
return STRNCASECMP(s1, s2, n);
516512
}

0 commit comments

Comments
 (0)