leo25 / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Reduce Stream's virtual write functions from 3 to 2. #607

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

The Stream write(const char *str) function does not need to be vitual.

Why?

Every library (Ethernet and SD) that optimizes multi-byte writes implements 
this by simply calling the block write using strlen.

Virtual functions are expensive.

Would this cause any incompatibilities with previous versions?  If so, how
can these be mitigated?

Only libraries which implement multi-byte writes are impacted.  So far, only SD 
and Ethernet do this.

Original issue reported on code.google.com by paul.sto...@gmail.com on 28 Aug 2011 at 6:53

GoogleCodeExporter commented 9 years ago
This patch makes Stream's write(const char *str) non-vitual.

Original comment by paul.sto...@gmail.com on 28 Aug 2011 at 6:56

Attachments:

GoogleCodeExporter commented 9 years ago
This patch makes Stream's write(const char *str) non-vitual, and also includes 
Alex Leone's suggestion to implement it inline for print().  This reduces the 
CPU time for string constants, but it results in slightly larger code size when 
I tested on the Ethernet Webserver example.

Original comment by paul.sto...@gmail.com on 28 Aug 2011 at 7:00

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks!

Do you have a recommendation for which version of the patch to use?  

Original comment by dmel...@gmail.com on 28 Aug 2011 at 7:17

GoogleCodeExporter commented 9 years ago
The smaller patch is safest.  The larger patch only adds optimization, not API 
changes.  With 1.0 so close, I would personally go with only the API change for 
now and consider the optimization later.

Original comment by paul.sto...@gmail.com on 29 Aug 2011 at 8:59

GoogleCodeExporter commented 9 years ago
This ended up being a bit more complicated.  I needed to add using 
Print::Write; various places to be able to still call the write(char *) version 
of the function.  Also, the Ethernet class names had changed.  Also, Wire 
implemented multi-byte write, too.  So you might want to take a look at the 
commit and see if it looks sane or not.  

https://github.com/arduino/Arduino/commit/7d8d20894c7420ad2fea81d80b660758064761
79

Original comment by dmel...@gmail.com on 7 Sep 2011 at 10:43