Skip to content

Commit

Permalink
⚡️ Tiny string optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Nov 23, 2023
1 parent 2d9262c commit bf61e52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Marlin/src/core/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ class SString : public MString<SIZE> {
SString& set() { super::set(); return *this; }

template<typename... Args>
SString& setf_P(PGM_P const fmt, Args... more) { snprintf_P(str, SIZE, fmt, more...); debug(F("setf_P")); return *this; }
SString& setf_P(PGM_P const fmt, Args... more) { super::setf_P(fmt, more...); return *this; }

template<typename... Args>
SString& setf(const char *fmt, Args... more) { snprintf(str, SIZE, fmt, more...); debug(F("setf")); return *this; }
SString& setf(const char *fmt, Args... more) { super::setf(fmt, more...); return *this; }

template<typename... Args>
SString& setf(FSTR_P const fmt, Args... more) { return setf_P(FTOP(fmt), more...); }
SString& setf(FSTR_P const fmt, Args... more) { super::setf(fmt, more...); return *this; }

template <typename T>
SString& set(const T &v) { super::set(v); return *this; }
Expand Down
18 changes: 13 additions & 5 deletions Marlin/src/lcd/menu/menu_ubl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,19 @@ void _lcd_ubl_storage_mesh() {
* UBL LCD "radar" map point editing
*/
void _lcd_ubl_map_edit_cmd() {
char ubl_lcd_gcode[50], str[10], str2[10];
dtostrf(bedlevel.get_mesh_x(x_plot), 0, 2, str);
dtostrf(bedlevel.get_mesh_y(y_plot), 0, 2, str2);
snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29P4X%sY%sR%i"), str, str2, int(n_edit_pts));
queue.inject(ubl_lcd_gcode);
#if ENABLED(POWER_LOSS_RECOVERY)
// Costs 198 bytes on AVR with PLR disabled, but saves 60 bytes with PLR enabled
queue.inject(TS(F("G29P4X"), x_plot, 'Y', y_plot, 'R', n_edit_pts));
#else
char ubl_lcd_gcode[50], str1[10], str2[10];
snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode),
PSTR("G29P4X%sY%sR%i"),
dtostrf(bedlevel.get_mesh_x(x_plot), 0, 2, str1),
dtostrf(bedlevel.get_mesh_y(y_plot), 0, 2, str2),
int(n_edit_pts)
);
queue.inject(ubl_lcd_gcode);
#endif
}

/**
Expand Down

0 comments on commit bf61e52

Please sign in to comment.