adafruit/Adafruit_CC3000_Library — pull request #64 by WashuHakubi (2014-04-07 01:53:26+00:00)
Title: Space savings through various modifications to CC3000 printer and state variables.

There is a heck of a lot of wasted space in the current library.

1. Variables that are significantly larger than necessary, or that may only be touched in one line of code.
2. Too many variables for something that could be represented with far fewer (such as using a bitset).
2. Printing code is always compiled in (currently) as the printer variable is external and non-const and thus the conditionals cannot be trivially elided by the compiler.

As this is used on embedded systems (arduino's) which usually only have about 30K of available program space, this is quite a significant issue, and a great deal of work should be put into optimizing the space used by program code to minimize waste.

In this case, I've applied some very basic space optimizations and have managed to net a bit over 2000 bytes of space back. That's two kilobytes (roughly) of space for user code.

The first is to introduce a bitset that is used in place of the volatile unsigned longs. This nets you approximately 400 bytes of program space.

The second is to introduce a macro which gates the CC3K printer at compile time. By then ensuring that all calls to the CC3K printer are gated with through this macro extensive space savings can be had due to string data that is NOT being stored anymore (when the gate is active).

Furthermore, this includes a few bug fixes, as there were several cases where the CC3K printer variable was accessed without a null pointer check.