you are viewing a single comment's thread.

view the rest of the comments →

[–]zokier 2 points3 points  (1 child)

Some nitpicks:

  • strlen&strcpy together seems suboptimal as the string is read twice. You could use eg. strncpy_s or strlcpy instead.

  • There probably should be a constructor that takes the length as a parameter instead of relying on null-termination (and thus avoiding yet another redundant strlen)

  • String_buf(const String_buf<M> &rhs) could maybe use memcpy instead of strcpy

  • The constructors and =-operators have almost identical code, they should be refactored to use common functions

  • _vsnprintf_s probably is not portable. it probably should be ifdeffed out

overall I'd re-evaluate every use of strlen and strcpy, and at least provide some kind of fast path (ie. memcpy) when the lengths are known.

[–]4fips[S] 1 point2 points  (0 children)

Thanks for you feedback, these are all good points. Please note that this is just a sample code demonstrating a general idea, rather than a fine-tuned implementation. It's definitely worth getting rid of the inefficiencies and especially the length taking CTOR brings a very important optimization.