Optimization of a Qt QByteArray conversion

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, ""));
}

• 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... – k06a May 25 '14 at 12:53

Try to avoid deep copying of source array, this can be achived with right method:
QByteArray restoreData(const QByteArray &data, char prepender = 'x')