Skip to content

Commit 33ad7e6

Browse files
committed
Another postfixes for PR #8418 (UNLIST function) by Alexey Chudaykin, based on reported QA issues
1 parent 4984551 commit 33ad7e6

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/jrd/recsrc/TableValueFunctionScan.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,30 +219,33 @@ void UnlistFunctionScan::internalOpen(thread_db* tdbb) const
219219
}
220220
else
221221
{
222-
const string& separatorStr = *impure->m_separatorStr;
222+
const std::string_view separatorView(impure->m_separatorStr->data(),
223+
impure->m_separatorStr->length());
223224
string valueStr(MOV_make_string2(tdbb, valueDesc, textType, true));
224-
auto end = AbstractString::npos;
225+
std::string_view valueView(valueStr.data(), valueStr.length());
226+
auto end = std::string_view::npos;
225227
do
226228
{
227-
auto size = end = valueStr.find(separatorStr);
228-
if (end == AbstractString::npos)
229+
auto size = end = valueView.find(separatorView);
230+
if (end == std::string_view::npos)
229231
{
230-
if (valueStr.hasData())
231-
size = valueStr.size();
232+
if (!valueView.empty())
233+
size = valueView.length();
232234
else
233235
break;
234236
}
235237

236238
if (size > 0)
237239
{
238240
dsc fromDesc;
239-
fromDesc.makeText(size, textType, (UCHAR*)(IPTR)(valueStr.c_str()));
241+
fromDesc.makeText(size, textType, (UCHAR*)(IPTR) valueView.data());
240242
assignParameter(tdbb, &fromDesc, toDesc, 0, record);
241243
impure->m_recordBuffer->store(record);
242244
}
243245

244-
valueStr.erase(valueStr.begin(), valueStr.begin() + end + separatorStr.length());
245-
} while (end != AbstractString::npos);
246+
valueView.remove_prefix(size + separatorView.length());
247+
248+
} while (end != std::string_view::npos);
246249
}
247250
}
248251

@@ -278,15 +281,24 @@ bool UnlistFunctionScan::nextBuffer(thread_db* tdbb) const
278281
impure->m_recordBuffer->store(record);
279282
};
280283

281-
MoveBuffer buffer;
282-
const auto address = buffer.getBuffer(MAX_COLUMN_SIZE);
283-
const auto length = impure->m_blob->BLB_get_data(tdbb, address, MAX_COLUMN_SIZE, false);
284-
if (length > 0)
284+
string bufferString;
285+
286+
if (impure->m_resultStr->hasData())
287+
bufferString = *impure->m_resultStr;
288+
289+
const auto resultLength = impure->m_resultStr->length();
290+
bufferString.reserve(MAX_COLUMN_SIZE + resultLength);
291+
const auto address = bufferString.begin() + resultLength;
292+
293+
const auto blobLength = impure->m_blob->BLB_get_data(tdbb, reinterpret_cast<UCHAR*>(address),
294+
MAX_COLUMN_SIZE, false);
295+
if (blobLength)
285296
{
286297
const std::string_view separatorView(impure->m_separatorStr->data(),
287298
impure->m_separatorStr->length());
288-
std::string_view valueView(reinterpret_cast<char*>(address), length);
299+
std::string_view valueView(bufferString.data(), blobLength + resultLength);
289300
auto end = std::string_view::npos;
301+
impure->m_resultStr->erase();
290302
do
291303
{
292304
auto size = end = valueView.find(separatorView);

0 commit comments

Comments
 (0)