Skip to content

Commit

Permalink
Remove Marshal::BinaryString
Browse files Browse the repository at this point in the history
Replace the custom (hackish) class with a simple (hackish) helper function.
This has the advantage of having one less Opal-specific class and avoids the
call to `super` when doing String#+.
  • Loading branch information
elia committed Dec 25, 2018
1 parent a31f2ab commit fef7ad3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
12 changes: 0 additions & 12 deletions opal/corelib/marshal.rb
Expand Up @@ -5,18 +5,6 @@ module Marshal
MAJOR_VERSION = 4
MINOR_VERSION = 8

# For simulating binary strings
#
class BinaryString < String
def encoding
Encoding::BINARY
end

def +(other)
BinaryString.new(super)
end
end

class << self
def dump(object)
WriteBuffer.new(object).write
Expand Down
14 changes: 11 additions & 3 deletions opal/corelib/marshal/write_buffer.rb
Expand Up @@ -182,9 +182,17 @@ module Marshal
class WriteBuffer
attr_reader :buffer

%x{
function binaryString(s) {
s = new String(s);
s.encoding = #{Encoding::BINARY};
return s;
}
}

def initialize(object)
@object = object
@buffer = BinaryString.new
@buffer = ''
@cache = []
@extends = Hash.new { |h, k| h[k] = [] }
append(version)
Expand Down Expand Up @@ -212,7 +220,7 @@ def write(object = @object)
end
end

@buffer
`binaryString(#{@buffer})`
end

def write_fixnum(n)
Expand Down Expand Up @@ -398,7 +406,7 @@ def write_ivars_prefix(object)
end

def append(s)
@buffer += s
`#{@buffer} += #{s}`
end

def version
Expand Down

0 comments on commit fef7ad3

Please sign in to comment.