Since heap calls will be quite expensive, the obvious optimization is to avoid them.
If you need to do this often, you could probably come up with some simple wrapper around the bare pointer that can express this.
Something like:
typedef struct {
const char *chars;
size_t offset;
} mystring;
Then you'd need to devise an API to convert a mystring *
into a character pointer, by adding the offset:
const char * mystring_get(const mystring *ms)
{
return ms->chars + ms->offset;
}
and of course a function to create a suffix where the 1st character is removed:
mystring mystring_tail(const mystring *ms)
{
const mystring suffix = { ms->chars, ms->offset + 1};
return suffix;
}
note that mystring_tail()
returns the new string structure by value, to avoid heap allocations.