8000 Remove strlen in calls like String::concat(s, strlen(s)) · mrengineer7777/ArduinoCore-API@184dd3e · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 184dd3e

Browse files
Remove strlen in calls like String::concat(s, strlen(s))
Instead of calling strlen in a dozen places, instead just call String::concat(s), which will then call strlen. This shrinks the code size of these calls significantly, the StringAppendOperator example on the Arduino Uno shrinks by 72 bytes. This change does incur a slight runtime cost, because there is one extra function call.
1 parent d5790a0 commit 184dd3e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

api/String.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,49 +307,49 @@ unsigned char String::concat(unsigned char num)
307307
{
308308
char buf[1 + 3 * sizeof(unsigned char)];
309309
itoa(num, buf, 10);
310-
return concat(buf, strlen(buf));
310+
return concat(buf);
311311
}
312312

313313
unsigned char String::concat(int num)
314314
{
315315
char buf[2 + 3 * sizeof(int)];
316316
itoa(num, buf, 10);
317-
return concat(buf, strlen(buf));
317+
return concat(buf);
318318
}
319319

320320
unsigned char String::concat(unsigned int num)
321321
{
322322
char buf[1 + 3 * sizeof(unsigned int)];
323323
utoa(num, buf, 10);
324-
return concat(buf, strlen(buf));
324+
return concat(buf);
325325
}
326326

327327
unsigned char String::concat(long num)
328328
{
329329
char buf[2 + 3 * sizeof(long)];
330330
ltoa(num, buf, 10);
331-
return concat(buf, strlen(buf));
331+
return concat(buf);
332332
}
333333

334334
unsigned char String::concat(unsigned long num)
335335
{
336336
char buf[1 + 3 * sizeof(unsigned long)];
337337
ultoa(num, buf, 10);
338-
return concat(buf, strlen(buf));
338+
return concat(buf);
339339
}
340340

341341
unsigned char String::concat(float num)
342342
{
343343
char buf[20];
344344
char* string = dtostrf(num, 4, 2, buf);
345-
return concat(string, strlen(string));
345+
return concat(string);
346346
}
347347

348348
unsigned char String::concat(double num)
349349
{
350350
char buf[20];
351351
char* string = dtostrf(num, 4, 2, buf);
352-
return concat(string, strlen(string));
352+
return concat(string);
353353
}
354354

355355
unsigned char String::concat(const __FlashStringHelper * str)
@@ -378,7 +378,7 @@ StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs)
378378
StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr)
379379
{
380380
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
381-
if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate();
381+
if (!cstr || !a.concat(cstr)) a.invalidate();
382382
return a;
383383
}
384384

0 commit comments

Comments
 (0)
0