Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1f1fe6a

Browse files
eileencodeskddnewton
authored andcommitted
bye bye buffer
1 parent ef9b974 commit 1f1fe6a

File tree

1 file changed

+1
-70
lines changed

1 file changed

+1
-70
lines changed

lib/syntax_tree/prism/prettier_print.rb

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -224,75 +224,6 @@ def type
224224
# cut down on allocations.
225225
TRIM = Trim.new.freeze
226226

227-
# When building up the contents in the output buffer, it's convenient to be
228-
# able to trim trailing whitespace before newlines. If the output object is a
229-
# string or array or strings, then we can do this with some gsub calls. If
230-
# not, then this effectively just wraps the output object and forwards on
231-
# calls to <<.
232-
module Buffer
233-
# This is an output buffer that wraps a string output object. It provides a
234-
# trim! method that trims off trailing whitespace from the string using
235-
# gsub!.
236-
class StringBuffer
237-
attr_reader :output
238-
239-
def initialize(output = "".dup)
240-
@output = output
241-
end
242-
243-
def <<(object)
244-
@output << object
245-
end
246-
247-
def trim!
248-
length = output.length
249-
output.gsub!(/[\t ]*\z/, "")
250-
length - output.length
251-
end
252-
end
253-
254-
# This is an output buffer that wraps an array output object. It provides a
255-
# trim! method that trims off trailing whitespace from the last element in
256-
# the array if it's an unfrozen string using the same method as the
257-
# StringBuffer.
258-
class ArrayBuffer
259-
attr_reader :output
260-
261-
def initialize(output = [])
262-
@output = output
263-
end
264-
265-
def <<(object)
266-
@output << object
267-
end
268-
269-
def trim!
270-
return 0 if output.empty?
271-
272-
trimmed = 0
273-
274-
while output.any? && output.last.is_a?(String) &&
275-
output.last.match?(/\A[\t ]*\z/)
276-
trimmed += output.pop.length
277-
end
278-
279-
if output.any? && output.last.is_a?(String) && !output.last.frozen?
280-
length = output.last.length
281-
output.last.gsub!(/[\t ]*\z/, "")
282-
trimmed += length - output.last.length
283-
end
284-
285-
trimmed
286-
end
287-
end
288-
289-
# This is a switch for building the correct output buffer wrapper class for
290-
# the given output object.
291-
def self.for(output)
292-
output.is_a?(String) ? StringBuffer.new(output) : ArrayBuffer.new(output)
293-
end
294-
end
295-
296227
# There are two modes in printing, break and flat. When we're in break mode,
297228
# any lines will use their newline, any if-breaks will use their break
298229
# contents, etc.
@@ -907,7 +838,7 @@ def fits?(next_commands, rest_commands, remaining)
907838
# This is our output buffer, really only necessary to keep track of
908839
# because we could encounter a Trim doc node that would actually add
909840
# remaining space.
910-
fit_buffer = buffer.class.new
841+
fit_buffer = []
911842

912843
while remaining >= 0
913844
if commands.empty?

0 commit comments

Comments
 (0)