I am working on a legacy C++ code and needs aggressive refactoring. Main problem in the code is, passing const char*
, char*
arguments heavily as below. const char*
variables are to pass internal char arrays (mostly user inputs) to validate and 'char*` to get any error details from the extended validators normally. This type of codes are everywhere in the codebase.
virtual bool ValidateField(const char* pointerToDataBuffer, char* error)
{
// extended codes by client teams.
}
I am thinking of changing the interfaces as below,
virtual bool ValidateField(const std::string copyOfBufferInside, std::string& error)
{
// do stuff as before.
}
My questions:
- Does this have huge performance issues? due to std::string construction. Normally internal buffers are about 0-31 in length, could increase in the future.
- Any other compact refactoring suggestions for this case, please suggest?
Note: Compiler is GCC 4.9.3.
EDITED: Internal buffer variables are in char[], not std::string. Might convert to std::string in the future. But that is not the case here.