\$\begingroup\$
\$\endgroup\$
1
I wrote a function to convert a hexadecimal string representation (like 0x00) of some binary data to the data itself.
How can I improve this code?
QByteArray restoreData(const QByteArray &data, const QString prepender = "x")
{
QByteArray restoredData = data;
return QByteArray::fromHex(restoredData.replace(prepender, ""));
}
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
-
1\$\begingroup\$ Why you need to improve this code? If you really need to do this, try to find way to create QByteArray without copying source data... \$\endgroup\$k06a– k06a2014年05月25日 12:53:04 +00:00Commented May 25, 2014 at 12:53
1 Answer 1
\$\begingroup\$
\$\endgroup\$
Try to avoid deep copying of source array, this can be achived with right
method:
QByteArray restoreData(const QByteArray &data, char prepender = 'x')
{
return QByteArray::fromHex(data.right(data.size() - data.indexOf(prepender) - 1);
}
lang-cpp