Skip to content

Commit

Permalink
Small format changes to StreamReader.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoglan committed Jul 7, 2015
1 parent 9165303 commit fed81a5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/websocket/driver/stream_reader.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module WebSocket
class Driver

class StreamReader
# Try to minimise the number of reallocations done:

This comment has been minimized.

Copy link
@ioquatix

ioquatix Jul 9, 2015

Contributor

The reason why I did not put it at the top is because I like to put constants as close as possible to where they are used. However, each to their own. I just thought I'd explain why.

MINIMUM_AUTOMATIC_PRUNE_OFFSET = 128

def initialize
@buffer = Driver.encode('', :binary)
@offset = 0
Expand All @@ -11,9 +15,6 @@ def put(buffer)
@buffer << Driver.encode(buffer, :binary)
end

# Try to minimise the number of reallocations done:
MINIMUM_AUTOMATIC_PRUNE_OFFSET = 128

# Read bytes from the data:
def read(length)
return nil if (@offset + length) > @buffer.bytesize
Expand All @@ -35,7 +36,7 @@ def each_byte
end
end

protected

This comment has been minimized.

Copy link
@ioquatix

ioquatix Jul 9, 2015

Contributor

The reason why it was protected is because I could imagine a derived class might want to explicitly prune, although it shouldn't be a public API for consumers of the stream.

This comment has been minimized.

Copy link
@jcoglan

jcoglan Jul 10, 2015

Author Collaborator

protected isn't necessary for subclasses to be able to use a method; subclasses can use their parents' private methods. protected means that a method can be called by other objects of the same type as the class where the method is defined.

This comment has been minimized.

Copy link
@ioquatix

ioquatix Jul 11, 2015

Contributor

Oh, yeah, that's correct. My bad. I assumed it was the same as private in C++.

private

def prune
buffer_size = @buffer.bytesize
Expand All @@ -48,7 +49,7 @@ def prune

@offset = 0
end

end

end
end

0 comments on commit fed81a5

Please sign in to comment.