Skip to content

Conversation

@cider101
Copy link

The member _startMillis in the class Stream is unneccesarry and can be replace with a local variable within the methods timedRead() and timedPeek(). This saves 4bytes per Stream instance...

timedPeek() {
   unsigned long start = millis();
   int c = peek();
    while(c < 0 && millis() - start < timout) {
      c = peek();
    }
    return c; 
 }

I guess, the implemenation above should produce less code then the original one with the do-while-loop. At least, i find it more readable.

Also, timedRead() could be implemented using timedPeek()

timedRead() {
    return timedPeek() < 0 ? -1 : read();
}

This again, should produce less code - At least, it removes doublicated code...

@matthijskooijman
Copy link
Collaborator

Hmm, seems this pullrequest didn't work out: there's unrelated commits in the pullrequest and I don't see any commit in there from you? Perhaps you should read up on how pullrequest work? :-)

Also, see my last comment on #1918 (and when you do add a proper commit to a pullrequest, use the text "Closes #1918" anywhere in the commit message to let github automatically close the issue when the code is merged).

Finally, I like your idea of implementing timedRead with timedPeek(), it looks good to me.

@matthijskooijman
Copy link
Collaborator

If you need more help with the pullrequest or code, feel free to drop by in #arduino on the Freenode IRC network. I'm called blathijs there :-)

@cider101
Copy link
Author

Perhaps you should read up on how pullrequest work? :-)

well, looks like that ;) Do i need to commit/checkin modified code first to create a pull request ?

@matthijskooijman
Copy link
Collaborator

Yes, see for example: http://yangsu.github.io/pull-request-tutorial/ (though note that it seems that tutorial just creates a new branch and pushes it out, but doesn't show actually adding commits to that new branch).

Reading up on git in general might also be useful, since I get the idea that you haven't worked with that either.

@cider101
Copy link
Author

fixed the zero-timeout issue... now it should behave as before and as one would guess with a zero timeout...

timedPeek() {
   unsigned long start = millis();
   int c = peek();
    while(c < 0 && millis() - start < timout) {
      c = peek();
    }
    return c; 
}

or even more compact (but less readable)

timedPeek() {
   unsigned long start = millis();
   int c;
   while((c = peek()) < 0 && (millis() - start < timout));
   return c; 
}

next thing is reading the tutorial on the pull-request ;)

@cider101 cider101 closed this Mar 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants