Optimize for speed

This commit is contained in:
fvanroie 2020-04-12 19:36:28 +02:00
parent 1333f632b7
commit 138f0fb3ee

View File

@ -2,25 +2,26 @@
#define _CHAR_STREAM_H_ #define _CHAR_STREAM_H_
#include <Stream.h> #include <Stream.h>
#include "Arduino.h"
class CharStream : public Stream { class CharStream : public Stream {
public: public:
CharStream(char * s) : string(s), position(0) CharStream(char * s) : string(s), position(0)
{} {
length = strlen(s);
}
// Stream methods // Stream methods
virtual int available() virtual int available()
{ {
return strlen(string) - position; return length - position;
} }
virtual int read() virtual int read()
{ {
return position < strlen(string) ? string[position++] : -1; return position < length ? string[position++] : -1;
} }
virtual int peek() virtual int peek()
{ {
return position < strlen(string) ? string[position] : -1; return position < length ? string[position] : -1;
} }
virtual void flush(){}; virtual void flush(){};
// Print methods // Print methods