Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd6d6c0

Browse files
committedDec 25, 2018
Remove Marshal::BinaryString
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#+.
1 parent a05f603 commit dd6d6c0

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed
 

‎opal/corelib/marshal.rb

-12
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ module Marshal
55
MAJOR_VERSION = 4
66
MINOR_VERSION = 8
77

8-
# For simulating binary strings
9-
#
10-
class BinaryString < String
11-
def encoding
12-
Encoding::BINARY
13-
end
14-
15-
def +(other)
16-
BinaryString.new(super)
17-
end
18-
end
19-
208
class << self
219
def dump(object)
2210
WriteBuffer.new(object).write

‎opal/corelib/marshal/write_buffer.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,17 @@ module Marshal
182182
class WriteBuffer
183183
attr_reader :buffer
184184

185+
%x{
186+
function binaryString(s) {
187+
s = new String(s);
188+
s.encoding = #{Encoding::BINARY};
189+
return s;
190+
}
191+
}
192+
185193
def initialize(object)
186194
@object = object
187-
@buffer = BinaryString.new
195+
@buffer = ''
188196
@cache = []
189197
@extends = Hash.new { |h, k| h[k] = [] }
190198
append(version)
@@ -212,7 +220,7 @@ def write(object = @object)
212220
end
213221
end
214222

215-
@buffer
223+
`binaryString(#{@buffer})`
216224
end
217225

218226
def write_fixnum(n)
@@ -398,7 +406,7 @@ def write_ivars_prefix(object)
398406
end
399407

400408
def append(s)
401-
@buffer += s
409+
`#{@buffer} += #{s}`
402410
end
403411

404412
def version

0 commit comments

Comments
 (0)
Please sign in to comment.