nasa / fpp

F Prime Prime: A modeling language for F Prime
https://fprime.jpl.nasa.gov
Apache License 2.0
41 stars 31 forks source link

Replace assignments to StringBase& in generated code #420

Closed bocchino closed 2 months ago

bocchino commented 2 months ago

Instead of sb = "foo" we should do sb.format("%s", "foo"). In some cases this will remove an extra buffer and an snprintf. Then we can make the copy assignment operator protected in the StringBase class.

timcanham commented 2 months ago

I've noticed during past projects that the format specifier strings can take up a lot of code, and the assignment operator is a natural way to code. Could we move the operator to the derived class?

bocchino commented 2 months ago

In most cases the proposed change will reduce code. For example instead of doing

we'll just do

In a few cases we'll have to add a format string "%s", but this is a negligible difference, and I think it only happens in unit tests. We could keep sb = "foo" in those cases, but then I think we'll need to have a public assignment operator in the base class, since the base class appears on the left-hand side of the assignment.

bocchino commented 2 months ago

Covered by #423. We can keep the assignment into StringBase for now, but we should remove the extra buffer copy where possible.