Skip to content

Commit

Permalink
Use Char for single char strings (crystal-lang#5882)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija authored and RX14 committed Mar 31, 2018
1 parent 4532389 commit 945557b
Show file tree
Hide file tree
Showing 85 changed files with 366 additions and 372 deletions.
2 changes: 1 addition & 1 deletion samples/sdl/tv.cr
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ end

def parse_rectangles
rects = [] of Rectangle
lines = File.read("#{__DIR__}/tv.txt").split("\n").map { |line| line.rstrip }
lines = File.read("#{__DIR__}/tv.txt").split('\n').map { |line| line.rstrip }
lines.each_with_index do |line, y|
x = 0
line.each_char do |c|
Expand Down
2 changes: 1 addition & 1 deletion samples/sudoku.cr
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ sudoku = "

def solve_all(sudoku)
mr, mc = sd_genmat()
sudoku.split("\n").map do |line|
sudoku.split('\n').map do |line|
if line.size >= 81
ret = sd_solve(mr, mc, line)
ret.map { |s2| s2.join }
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_windows_zone_names.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ hash_items = String.build do |io|
entry[:key].inspect(io)
io << " => "
entry[:zones].inspect(io)
io << ", # " << entry[:tzdata_name] << "\n"
io << ", # " << entry[:tzdata_name] << '\n'
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/crystal/tools/expand_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,6 @@ describe "expand" do
end
CODE

assert_expand_simple code, original: "foo(hello)", expanded: expanded + "\n"
assert_expand_simple code, original: "foo(hello)", expanded: expanded + '\n'
end
end
2 changes: 1 addition & 1 deletion spec/std/ecr/ecr_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe "ECR" do
%(__str__ << " "),
%(__str__ << "<% \\"string\\" %>"),
]
program.should eq(pieces.join("\n") + "\n")
program.should eq(pieces.join('\n') + '\n')
end

it "does ECR.def_to_s" do
Expand Down
4 changes: 2 additions & 2 deletions spec/std/http/formdata/builder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe HTTP::FormData::Builder do
--fixed-boundary--
MULTIPART

generated.should eq(expected.gsub("\n", "\r\n"))
generated.should eq(expected.gsub('\n', "\r\n"))
end

describe "#field" do
Expand All @@ -54,7 +54,7 @@ describe HTTP::FormData::Builder do
--fixed-boundary--
MULTIPART

generated.should eq(expected.gsub("\n", "\r\n"))
generated.should eq(expected.gsub('\n', "\r\n"))
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/formdata/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe HTTP::FormData::Parser do
-----------------------------735323031399963166993862150--
FORMDATA

parser = HTTP::FormData::Parser.new IO::Memory.new(formdata.gsub("\n", "\r\n")), "---------------------------735323031399963166993862150"
parser = HTTP::FormData::Parser.new IO::Memory.new(formdata.gsub('\n', "\r\n")), "---------------------------735323031399963166993862150"

runs = 0
while parser.has_next?
Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/headers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe HTTP::Headers do
headers = HTTP::Headers{"FOO_BAR" => "bar", "Foobar-foo" => "baz"}
serialized = String.build do |io|
headers.each do |name, values|
io << name << ": " << values.first << ";"
io << name << ": " << values.first << ';'
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/std/http/multipart/builder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe HTTP::Multipart::Builder do
--fixed-boundary--
MULTIPART

io.to_s.should eq(expected_message.gsub("\n", "\r\n"))
io.to_s.should eq(expected_message.gsub('\n', "\r\n"))
end

it "generates valid multipart messages with preamble and epilogue" do
Expand Down Expand Up @@ -59,7 +59,7 @@ describe HTTP::Multipart::Builder do
Irelevant textMuch more irelevant text
MULTIPART

io.to_s.should eq(expected_message.gsub("\n", "\r\n"))
io.to_s.should eq(expected_message.gsub('\n', "\r\n"))
end

describe "#content_type" do
Expand Down Expand Up @@ -99,7 +99,7 @@ describe HTTP::Multipart::Builder do
--boundary--
MULTIPART

generated_multipart.should eq(expected_multipart.gsub("\n", "\r\n"))
generated_multipart.should eq(expected_multipart.gsub('\n', "\r\n"))
end

it "raises when called after starting the body" do
Expand Down Expand Up @@ -156,7 +156,7 @@ describe HTTP::Multipart::Builder do
--boundary--
MULTIPART

generated_multipart.should eq(expected_multipart.gsub("\n", "\r\n"))
generated_multipart.should eq(expected_multipart.gsub('\n', "\r\n"))
end

it "raises when called after finishing" do
Expand Down Expand Up @@ -211,7 +211,7 @@ describe HTTP::Multipart::Builder do
MULTIPART

generated_multipart.should eq(expected_multipart.gsub("\n", "\r\n"))
generated_multipart.should eq(expected_multipart.gsub('\n', "\r\n"))
end

it "raises when called after finishing" do
Expand Down
6 changes: 3 additions & 3 deletions spec/std/http/multipart/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "spec"
require "http"

private def parse(delim, data, *, gsub = true)
data_io = IO::Memory.new(gsub ? data.gsub("\n", "\r\n") : data)
data_io = IO::Memory.new(gsub ? data.gsub('\n', "\r\n") : data)
parser = HTTP::Multipart::Parser.new(data_io, delim)

parsed = [] of {headers: HTTP::Headers, body: String}
Expand Down Expand Up @@ -89,7 +89,7 @@ describe HTTP::Multipart::Parser do
Foo
--AaB03x--
MULTIPART
parser = HTTP::Multipart::Parser.new(IO::Memory.new(input.gsub("\n", "\r\n")), "AaB03x")
parser = HTTP::Multipart::Parser.new(IO::Memory.new(input.gsub('\n', "\r\n")), "AaB03x")

parser.next { }
parser.has_next?.should eq(false)
Expand Down Expand Up @@ -126,7 +126,7 @@ describe HTTP::Multipart::Parser do
--b--
MULTIPART

parser = HTTP::Multipart::Parser.new(IO::Memory.new(input.gsub("\n", "\r\n")), "b")
parser = HTTP::Multipart::Parser.new(IO::Memory.new(input.gsub('\n', "\r\n")), "b")

ios = [] of IO

Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/server/server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -350,5 +350,5 @@ module HTTP
end

private def requestize(string)
string.gsub("\n", "\r\n")
string.gsub('\n', "\r\n")
end
6 changes: 3 additions & 3 deletions spec/std/io/io_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ describe IO do

it "gets with single byte string as delimiter" do
io = SimpleIOMemory.new("hello\nworld\nbye")
io.gets("\n").should eq("hello\n")
io.gets("\n").should eq("world\n")
io.gets("\n").should eq("bye")
io.gets('\n').should eq("hello\n")
io.gets('\n').should eq("world\n")
io.gets('\n').should eq("bye")
end

it "does gets with limit" do
Expand Down
2 changes: 1 addition & 1 deletion spec/std/logger_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe "Logger" do
IO.pipe do |r, w|
logger = Logger.new(w)
logger.formatter = Logger::Formatter.new do |severity, datetime, progname, message, io|
io << severity.to_s[0] << " " << progname << ": " << message
io << severity.to_s[0] << ' ' << progname << ": " << message
end
logger.warn "message", "prog"

Expand Down
4 changes: 2 additions & 2 deletions spec/std/spec/junit_formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe "JUnit Formatter" do
name.should eq("Something happened")

backtrace = xml.xpath_string("string(//testsuite/testcase[1]/failure/text())")
backtrace.should eq(cause.backtrace.join("\n"))
backtrace.should eq(cause.backtrace.join('\n'))
end

it "report error stacktrace if present" do
Expand All @@ -115,7 +115,7 @@ describe "JUnit Formatter" do
name.should eq("Something happened")

backtrace = xml.xpath_string("string(//testsuite/testcase[1]/error/text())")
backtrace.should eq(cause.backtrace.join("\n"))
backtrace.should eq(cause.backtrace.join('\n'))
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1657,9 +1657,9 @@ class Array(T)

def to_s(io : IO)
executed = exec_recursive(:to_s) do
io << "["
io << '['
join ", ", io, &.inspect(io)
io << "]"
io << ']'
end
io << "[...]" unless executed
end
Expand Down
4 changes: 2 additions & 2 deletions src/bit_array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ struct BitArray
def to_s(io : IO)
io << "BitArray["
each do |value|
io << (value ? "1" : "0")
io << (value ? '1' : '0')
end
io << "]"
io << ']'
end

# ditto
Expand Down
4 changes: 2 additions & 2 deletions src/char.cr
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ struct Char
if ascii_control?
io << "\\u{"
ord.to_s(16, io)
io << "}"
io << '}'
else
to_s(io)
end
Expand Down Expand Up @@ -507,7 +507,7 @@ struct Char
if ascii_control? || ord >= 0x80
io << "\\u{"
ord.to_s(16, io)
io << "}"
io << '}'
else
to_s(io)
end
Expand Down
24 changes: 12 additions & 12 deletions src/colorize.cr
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ struct Colorize::Object(T)
private BACK_LIGHT_CYAN = "106"
private BACK_WHITE = "107"

private MODE_DEFAULT = "0"
private MODE_BOLD = "1"
private MODE_BRIGHT = "1"
private MODE_DIM = "2"
private MODE_UNDERLINE = "4"
private MODE_BLINK = "5"
private MODE_REVERSE = "7"
private MODE_HIDDEN = "8"
private MODE_DEFAULT = '0'
private MODE_BOLD = '1'
private MODE_BRIGHT = '1'
private MODE_DIM = '2'
private MODE_UNDERLINE = '4'
private MODE_BLINK = '5'
private MODE_REVERSE = '7'
private MODE_HIDDEN = '8'

private MODE_BOLD_FLAG = 1
private MODE_BRIGHT_FLAG = 1
Expand Down Expand Up @@ -304,13 +304,13 @@ struct Colorize::Object(T)
end

unless fore_is_default
io << ";" if printed
io << ';' if printed
io << @fore
printed = true
end

unless back_is_default
io << ";" if printed
io << ';' if printed
io << @back
printed = true
end
Expand All @@ -319,14 +319,14 @@ struct Colorize::Object(T)
# Can't reuse MODES constant because it has bold/bright duplicated
{% for name in %w(bold dim underline blink reverse hidden) %}
if @mode.bits_set? MODE_{{name.upcase.id}}_FLAG
io << ";" if printed
io << ';' if printed
io << MODE_{{name.upcase.id}}
printed = true
end
{% end %}
end

io << "m"
io << 'm'

true
end
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/crystal/codegen/asm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ class Crystal::CodeGenVisitor
input_values = [] of LLVM::Value

if inputs = node.inputs
constraints << "," unless constraints.empty?
constraints << ',' unless constraints.empty?

inputs.each_with_index do |input, i|
accept input.exp
input_types << llvm_type(input.exp.type)
input_values << @last
constraints << "," if i > 0
constraints << ',' if i > 0
constraints << input.constraint
end
end

if clobbers = node.clobbers
constraints << "," unless constraints.empty?
constraints << ',' unless constraints.empty?

clobbers.each_with_index do |clobber, i|
constraints << "," if i > 0
constraints << ',' if i > 0
constraints << "~{"
constraints << clobber
constraints << '}'
Expand Down
18 changes: 9 additions & 9 deletions src/compiler/crystal/codegen/ast.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,36 @@ module Crystal

def mangled_name(program, self_type)
name = String.build do |str|
str << "*"
str << '*'

if owner = @owner
if owner.metaclass?
self_type.instance_type.llvm_name(str)
if original_owner != self_type
str << "@"
str << '@'
original_owner.instance_type.llvm_name(str)
end
str << "::"
elsif !owner.is_a?(Crystal::Program)
self_type.llvm_name(str)
if original_owner != self_type
str << "@"
str << '@'
original_owner.llvm_name(str)
end
str << "#"
str << '#'
end
end

str << self.name.gsub('@', '.')

next_def = self.next
while next_def
str << "'"
str << '\''
next_def = next_def.next
end

if args.size > 0 || uses_block_arg?
str << "<"
str << '<'
if args.size > 0
args.each_with_index do |arg, i|
str << ", " if i > 0
Expand All @@ -75,13 +75,13 @@ module Crystal
end
if uses_block_arg?
str << ", " if args.size > 0
str << "&"
str << '&'
block_arg.not_nil!.type.llvm_name(str)
end
str << ">"
str << '>'
end
if return_type = @type
str << ":"
str << ':'
return_type.llvm_name(str)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/cache_dir.cr
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module Crystal
io.puts "Crystal needs a cache directory. These directories were candidates for it:"
io.puts
candidates.each do |candidate|
io << " - " << candidate << "\n"
io << " - " << candidate << '\n'
end
io.puts
io.puts "but none of them are writable."
Expand Down
Loading

0 comments on commit 945557b

Please sign in to comment.