Skip to content

Commit

Permalink
Use more chars instead of strings (#6237)
Browse files Browse the repository at this point in the history
  • Loading branch information
wooster0 authored and bcardiff committed Apr 5, 2019
1 parent 23a7cca commit 359f57c
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 39 deletions.
8 changes: 4 additions & 4 deletions samples/2048.cr
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Drawer
end

def space_line
line "", " ", "", ""
line '│', " ", '│', '│'
end

def content_line
Expand All @@ -126,15 +126,15 @@ class Drawer
end

def top_border
line "", "", "", ""
line '┌', "", '┬', '┐'
end

def mid_border
line "", "", "", ""
line '├', "", '┼', '┤'
end

def bottom_border
line "", "", "", ""
line '└', "", '┴', '┘'
end

def line(left, fill, inner, right)
Expand Down
2 changes: 1 addition & 1 deletion samples/havlak.cr
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ puts "Another 50 iterations..."

sum = 0
50.times do |i|
print "."
print '.'
sum += HavlakLoopFinder.new(TOP_CFG, LSG.new).find_loops
end

Expand Down
13 changes: 4 additions & 9 deletions samples/llvm/brainfuck.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ require "llvm"
NUM_CELLS = 30000
CELL_SIZE_IN_BYTES = 1

def error(message)
puts message
exit 1
end

abstract class Instruction
abstract def compile(program, bb)
end
Expand Down Expand Up @@ -166,12 +161,12 @@ class Program
when '['
matching_close_index = find_matching_close(source, i)
unless matching_close_index
error "Unmatched '[' at position #{i}"
abort "Unmatched '[' at position #{i}"
end
program << Loop.new(parse(source, i + 1, matching_close_index))
i = matching_close_index
when ']'
error "Unmatched ']' at position #{i}"
abort "Unmatched ']' at position #{i}"
end
i += 1
end
Expand Down Expand Up @@ -253,11 +248,11 @@ end

filename = ARGV.first?
unless filename
error "Missing filename"
abort "Missing filename"
end

unless File.file?(filename)
error "'#{filename} is not a file"
abort "#{filename} is not a file"
end

source = File.read(filename)
Expand Down
4 changes: 2 additions & 2 deletions samples/meteor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def print_sol(str)
i = 0
str.each_byte do |c|
puts if i % 5 == 0
print " " if (i + 5) % 10 == 0
print " "
print ' ' if (i + 5) % 10 == 0
print ' '
print c.chr
i += 1
end
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/crystal/tools/context_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private def run_context_tool(code)
end
end

code = code.gsub('‸', "")
code = code.delete('‸')

if cursor_location
visitor, result = processed_context_visitor(code, cursor_location)
Expand Down
6 changes: 3 additions & 3 deletions spec/compiler/crystal/tools/expand_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private def run_expand_tool(code)
end
end

code = code.gsub('‸', "")
code = code.delete('‸')

if cursor_location
visitor, result = processed_expand_visitor(code, cursor_location)
Expand Down Expand Up @@ -55,11 +55,11 @@ private def assert_expand(code, expected_result)
end
end

private def assert_expand_simple(code, expanded, original = code.gsub('‸', ""))
private def assert_expand_simple(code, expanded, original = code.delete('‸'))
assert_expand_simple(code, expanded, original) { }
end

private def assert_expand_simple(code, expanded, original = code.gsub('‸', ""))
private def assert_expand_simple(code, expanded, original = code.delete('‸'))
assert_expand(code, [[original, expanded]]) { |result| yield result.expansions.not_nil![0] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/crystal/tools/implementations_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private def assert_implementations(code)
end
end

code = code.gsub('‸', "").gsub('༓', "")
code = code.delete { |char| {'‸', '༓'}.includes? char }

if cursor_location
visitor, result = processed_implementation_visitor(code, cursor_location)
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/lexer/lexer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ end
private def it_lexes_symbols(symbols)
symbols.each do |symbol|
value = symbol[1, symbol.size - 1]
value = value[1, value.size - 2] if value.starts_with?("\"")
value = value[1, value.size - 2] if value.starts_with?('"')
it_lexes symbol, :SYMBOL, value
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module Crystal
":>=", ":!", ":!=", ":=~", ":!~", ":&", ":|", ":^", ":~", ":**", ":>>", ":<<", ":%", ":[]", ":[]?",
":[]=", ":<=>", ":==="].each do |symbol|
value = symbol[1, symbol.size - 1]
value = value[1, value.size - 2] if value.starts_with?("\"")
value = value[1, value.size - 2] if value.starts_with?('"')
it_parses symbol, value.symbol
end
it_parses ":foo", "foo".symbol
Expand Down
22 changes: 11 additions & 11 deletions src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -555,21 +555,21 @@ module Crystal
when '\\'
case char = next_char
when 'a'
io << "\u{7}"
io << '\a'
when 'b'
io << "\u{8}"
io << '\b'
when 'n'
io << "\n"
io << '\n'
when 'r'
io << "\r"
io << '\r'
when 't'
io << "\t"
io << '\t'
when 'v'
io << "\v"
io << '\v'
when 'f'
io << "\f"
io << '\f'
when 'e'
io << "\e"
io << '\e'
when 'x'
io.write_byte consume_string_hex_escape
when 'u'
Expand All @@ -578,7 +578,7 @@ module Crystal
io.write_byte consume_octal_escape(char)
when '\n'
incr_line_number nil
io << "\n"
io << '\n'
when '\0'
raise "unterminated quoted symbol", line, column
else
Expand Down Expand Up @@ -1928,9 +1928,9 @@ module Crystal
else
case char = next_char
when 'a'
string_token_escape_value "\u{7}"
string_token_escape_value "\a"
when 'b'
string_token_escape_value "\u{8}"
string_token_escape_value "\b"
when 'n'
string_token_escape_value "\n"
when 'r'
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/doc/macro.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Crystal::Doc::Macro

def id
String.build do |io|
io << to_s.gsub(/<.+?>/, "").gsub(' ', "")
io << to_s.gsub(/<.+?>/, "").delete(' ')
io << "-macro"
end
end
Expand All @@ -39,7 +39,7 @@ class Crystal::Doc::Macro
end

def anchor
"#" + URI.escape(id)
'#' + URI.escape(id)
end

def prefix
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/doc/method.cr
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Crystal::Doc::Method

def id
String.build do |io|
io << to_s.gsub(/<.+?>/, "").gsub(' ', "")
io << to_s.gsub(/<.+?>/, "").delete(' ')
if @class_method
io << "-class-method"
else
Expand Down
2 changes: 1 addition & 1 deletion src/string.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3867,7 +3867,7 @@ class String
printed_bytesize += part.bytesize
if printed_bytesize != bytesize
printed_bytesize += 1 # == "\n".bytesize
pp.text("\"")
pp.text('"')
pp.text(part.inspect_unquoted)
pp.text("\\n\"")
break if printed_bytesize == bytesize
Expand Down
2 changes: 1 addition & 1 deletion src/uri/punycode.cr
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class URI
first = true
string.split('.') do |part|
unless first
io << "."
io << '.'
end

if part.ascii_only?
Expand Down

0 comments on commit 359f57c

Please sign in to comment.