-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
- Loading branch information
There are no files selected for viewing
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.
Sorry, something went wrong. |
||
MINIMUM_AUTOMATIC_PRUNE_OFFSET = 128 | ||
|
||
def initialize | ||
@buffer = Driver.encode('', :binary) | ||
@offset = 0 | ||
|
@@ -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 | ||
|
@@ -35,7 +36,7 @@ def each_byte | |
end | ||
end | ||
|
||
protected | ||
This comment has been minimized.
Sorry, something went wrong.
ioquatix
Contributor
|
||
private | ||
|
||
def prune | ||
buffer_size = @buffer.bytesize | ||
|
@@ -48,7 +49,7 @@ def prune | |
|
||
@offset = 0 | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
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.