Skip to content

Commit 3c9c10f

Browse files
committed
constexpr in BlobWrapper/UserBlob
1 parent 9046f49 commit 3c9c10f

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/common/classes/BlobWrapper.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "ibase.h"
2828
#include "firebird/Interface.h"
2929

30-
static const USHORT SEGMENT_LIMIT = 65535;
30+
static constexpr USHORT SEGMENT_LIMIT = 65535;
3131

3232
using namespace Firebird;
3333

@@ -92,9 +92,9 @@ bool BlobWrapper::getSegment(FB_SIZE_T len, void* buffer, FB_SIZE_T& real_len)
9292
if (len && !buffer)
9393
return false;
9494

95-
unsigned ilen = len > SEGMENT_LIMIT ? SEGMENT_LIMIT : static_cast<unsigned>(len);
95+
const unsigned ilen = MIN(len, SEGMENT_LIMIT);
9696
unsigned olen = 0;
97-
bool eof = m_blob->getSegment(m_status, ilen, buffer, &olen) == Firebird::IStatus::RESULT_NO_DATA;
97+
const bool eof = m_blob->getSegment(m_status, ilen, buffer, &olen) == Firebird::IStatus::RESULT_NO_DATA;
9898
if (m_status->isEmpty() && !eof)
9999
{
100100
real_len = olen;
@@ -120,8 +120,8 @@ bool BlobWrapper::getData(FB_SIZE_T len, void* buffer, FB_SIZE_T& real_len,
120120
while (len)
121121
{
122122
unsigned olen = 0;
123-
unsigned ilen = MIN(len, SEGMENT_LIMIT);
124-
bool eof = m_blob->getSegment(m_status, ilen, buf2, &olen) == Firebird::IStatus::RESULT_NO_DATA;
123+
const unsigned ilen = MIN(len, SEGMENT_LIMIT);
124+
const bool eof = m_blob->getSegment(m_status, ilen, buf2, &olen) == Firebird::IStatus::RESULT_NO_DATA;
125125
if (m_status->isEmpty() && !eof)
126126
{
127127
len -= olen;
@@ -154,7 +154,7 @@ bool BlobWrapper::putSegment(FB_SIZE_T len, const void* buffer)
154154
return false;
155155
#endif
156156

157-
unsigned ilen = len > SEGMENT_LIMIT ? SEGMENT_LIMIT : static_cast<unsigned>(len);
157+
const unsigned ilen = MIN(len, SEGMENT_LIMIT);
158158
m_blob->putSegment(m_status, ilen, buffer);
159159
return m_status->isEmpty();
160160
}

src/common/classes/UserBlob.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
#include "ibase.h"
2626
#include "../yvalve/gds_proto.h"
2727

28-
static const USHORT SEGMENT_LIMIT = 65535;
29-
//static SLONG fb_vax_integer(const UCHAR* ptr, int length);
28+
static constexpr USHORT SEGMENT_LIMIT = 65535;
3029

3130

3231
bool UserBlob::open(FB_API_HANDLE& db, FB_API_HANDLE& trans, ISC_QUAD& blobid)
@@ -117,7 +116,7 @@ bool UserBlob::getSegment(FB_SIZE_T len, void* buffer, FB_SIZE_T& real_len)
117116
#endif
118117

119118
USHORT olen = 0;
120-
USHORT ilen = len > SEGMENT_LIMIT ? SEGMENT_LIMIT : static_cast<USHORT>(len);
119+
const USHORT ilen = len > SEGMENT_LIMIT ? SEGMENT_LIMIT : static_cast<USHORT>(len);
121120
char* buf2 = static_cast<char*>(buffer);
122121
if (!isc_get_segment(m_status, &m_blob, &olen, ilen, buf2) || m_status[1] == isc_segment)
123122
{
@@ -142,7 +141,7 @@ bool UserBlob::getData(FB_SIZE_T len, void* buffer, FB_SIZE_T& real_len,
142141
while (len)
143142
{
144143
USHORT olen = 0;
145-
USHORT ilen = len > SEGMENT_LIMIT ? SEGMENT_LIMIT : static_cast<USHORT>(len);
144+
const USHORT ilen = len > SEGMENT_LIMIT ? SEGMENT_LIMIT : static_cast<USHORT>(len);
146145
if (!isc_get_segment(m_status, &m_blob, &olen, ilen, buf2) || m_status[1] == isc_segment)
147146
{
148147
len -= olen;
@@ -172,7 +171,7 @@ bool UserBlob::putSegment(FB_SIZE_T len, const void* buffer)
172171
return false;
173172
#endif
174173

175-
USHORT ilen = len > SEGMENT_LIMIT ? SEGMENT_LIMIT : static_cast<USHORT>(len);
174+
const USHORT ilen = len > SEGMENT_LIMIT ? SEGMENT_LIMIT : static_cast<USHORT>(len);
176175
const char* buf2 = static_cast<const char*>(buffer);
177176
return !isc_put_segment(m_status, &m_blob, ilen, buf2);
178177
}
@@ -227,8 +226,8 @@ bool UserBlob::getInfo(FB_SIZE_T items_size, const UCHAR* items,
227226
return false;
228227

229228
// We have to cater for the API limitations.
230-
SSHORT in_len = items_size > MAX_SSHORT ? MAX_SSHORT : static_cast<SSHORT>(items_size);
231-
SSHORT out_len = info_size > MAX_SSHORT ? MAX_SSHORT : static_cast<SSHORT>(info_size);
229+
const SSHORT in_len = static_cast<SSHORT>(MIN(items_size, MAX_SSHORT));
230+
const SSHORT out_len = static_cast<SSHORT>(MIN(info_size, MAX_SSHORT));
232231
// That the API declares the second param as non const is a bug.
233232
FB_API_HANDLE blob = m_blob;
234233
return !isc_blob_info(m_status, &blob,

0 commit comments

Comments
 (0)