Skip to content

Commit

Permalink
Use Char instead of String in split/join calls whenever possible (#5963)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija authored and sdogruyol committed Apr 19, 2018
1 parent aa596d3 commit 6c40696
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions spec/compiler/codegen/macro_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ describe "Code gen: macro" do
@x = 1; @x = 1.1
end
def foo
{{ @type.instance_vars.first.type.union_types.map(&.name).sort }}.join("-")
{{ @type.instance_vars.first.type.union_types.map(&.name).sort }}.join('-')
end
end
Foo.new.foo
Expand Down Expand Up @@ -599,7 +599,7 @@ describe "Code gen: macro" do
require "prelude"
class Foo(T, K)
def self.foo : String
{{ @type.type_vars.map(&.stringify) }}.join("-")
{{ @type.type_vars.map(&.stringify) }}.join('-')
end
end
Foo.foo
Expand Down Expand Up @@ -693,7 +693,7 @@ describe "Code gen: macro" do
end
names = {{ Foo.subclasses.map &.name }}
names.join("-")
names.join('-')
)).to_string.should eq("Bar-Baz")
end

Expand All @@ -711,7 +711,7 @@ describe "Code gen: macro" do
end
names = {{ Foo.all_subclasses.map &.name }}
names.join("-")
names.join('-')
)).to_string.should eq("Bar-Baz")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/macro/macro_methods_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe "macro methods" do
end

it "executes split with argument" do
assert_macro "", %({{"1-2-3".split("-")}}), [] of ASTNode, %(["1", "2", "3"] of ::String)
assert_macro "", %({{"1-2-3".split('-')}}), [] of ASTNode, %(["1", "2", "3"] of ::String)
end

it "executes split with char argument" do
Expand Down
6 changes: 3 additions & 3 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ describe "File" do
it "converts a pathname to an absolute pathname, using ~ (home) as base" do
File.expand_path("~/").should eq(home)
File.expand_path("~/..badfilename").should eq(File.join(home, "..badfilename"))
File.expand_path("..").should eq("/#{base.split("/")[0...-1].join("/")}".gsub(%r{\A//}, "/"))
File.expand_path("..").should eq("/#{base.split('/')[0...-1].join('/')}".gsub(%r{\A//}, "/"))
File.expand_path("~/a", "~/b").should eq(File.join(home, "a"))
File.expand_path("~").should eq(home)
File.expand_path("~", "/tmp/gumby/ddd").should eq(home)
Expand All @@ -578,7 +578,7 @@ describe "File" do
ENV["HOME"] = __DIR__ + "/"
File.expand_path("~/").should eq(home)
File.expand_path("~/..badfilename").should eq(File.join(home, "..badfilename"))
File.expand_path("..").should eq("/#{base.split("/")[0...-1].join("/")}".gsub(%r{\A//}, "/"))
File.expand_path("..").should eq("/#{base.split('/')[0...-1].join('/')}".gsub(%r{\A//}, "/"))
File.expand_path("~/a", "~/b").should eq(File.join(home, "a"))
File.expand_path("~").should eq(home)
File.expand_path("~", "/tmp/gumby/ddd").should eq(home)
Expand All @@ -594,7 +594,7 @@ describe "File" do
ENV["HOME"] = "/"
File.expand_path("~/").should eq(home)
File.expand_path("~/..badfilename").should eq(File.join(home, "..badfilename"))
File.expand_path("..").should eq("/#{base.split("/")[0...-1].join("/")}".gsub(%r{\A//}, "/"))
File.expand_path("..").should eq("/#{base.split('/')[0...-1].join('/')}".gsub(%r{\A//}, "/"))
File.expand_path("~/a", "~/b").should eq(File.join(home, "a"))
File.expand_path("~").should eq(home)
File.expand_path("~", "/tmp/gumby/ddd").should eq(home)
Expand Down
2 changes: 1 addition & 1 deletion spec/std/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ describe "String" do
it { "foo ".split(' ').should eq(["foo", "", "", ""]) }
it { " foo bar".split(' ').should eq(["", "", "", "foo", "", "bar"]) }
it { " foo bar\n\t baz ".split(' ').should eq(["", "", "", "foo", "", "", "bar\n\t", "", "baz", "", "", ""]) }
it { " foo bar\n\t baz ".split(" ").should eq(["", "", "", "foo", "", "", "bar\n\t", "", "baz", "", "", ""]) }
it { " foo bar\n\t baz ".split(' ').should eq(["", "", "", "foo", "", "", "bar\n\t", "", "baz", "", "", ""]) }
it { "foo,bar,baz,qux".split(',', 1).should eq(["foo,bar,baz,qux"]) }
it { "foo,bar,baz,qux".split(',', 3).should eq(["foo", "bar", "baz,qux"]) }
it { "foo,bar,baz,qux".split(',', 30).should eq(["foo", "bar", "baz", "qux"]) }
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class Crystal::Command
end

unless no_codegen
opts.on("--emit [#{VALID_EMIT_VALUES.join("|")}]", "Comma separated list of types of output for the compiler to emit") do |emit_values|
opts.on("--emit [#{VALID_EMIT_VALUES.join('|')}]", "Comma separated list of types of output for the compiler to emit") do |emit_values|
compiler.emit = validate_emit_values(emit_values.split(',').map(&.strip))
end
end
Expand Down Expand Up @@ -426,7 +426,7 @@ class Crystal::Command
end
end

compiler.link_flags = link_flags.join(" ") unless link_flags.empty?
compiler.link_flags = link_flags.join(' ') unless link_flags.empty?

output_filename = opt_output_filename
filenames += opt_filenames.not_nil!
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module Crystal

# On release: 0.0.0-0-gabcd123
# Ahead of last release: 0.0.0-42-gabcd123
tag, commits, sha = git_version.split("-")
tag, commits, sha = git_version.split('-')
sha = sha[1..-1] # Strip g
tag = "#{tag}+#{commits}" unless commits == "0" # Reappend commits since release unless we hit it exactly

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/bindings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ module Crystal
end

if types.size > 300
raise "tuple too big: Tuple(#{types[0...10].join(",")}, ...)"
raise "tuple too big: Tuple(#{types[0...10].join(',')}, ...)"
end

self.type = tuple_type
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/init.cr
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ module Crystal
end

def module_name
config.name.split("-").map(&.camelcase).join("::")
config.name.split('-').map(&.camelcase).join("::")
end

abstract def full_path
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/bcrypt/password.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Crypto::Bcrypt::Password
# password.digest # => "8/Po4wTL0fhdDNdAdjcKN/Fup8tGCya"
# ```
def initialize(@raw_hash : String)
parts = @raw_hash.split("$")
parts = @raw_hash.split('$')

@version = parts[1]
@cost = parts[2].to_i
Expand Down
2 changes: 1 addition & 1 deletion src/option_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class OptionParser
end

private def process_double_flag(flag, block, raise_if_missing = false)
while index = args_index { |arg| arg.split("=")[0] == flag }
while index = args_index { |arg| arg.split('=')[0] == flag }
arg = @args[index]
if arg.size == flag.size
delete_arg_at_index(index)
Expand Down
2 changes: 1 addition & 1 deletion src/regex.cr
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class Regex
# re.match("sledding") # => #<Regex::MatchData "sledding">
# ```
def self.union(patterns : Enumerable(Regex | String)) : self
new patterns.map { |pattern| union_part pattern }.join("|")
new patterns.map { |pattern| union_part pattern }.join('|')
end

# Union. Returns a `Regex` that matches any of *patterns*.
Expand Down
2 changes: 1 addition & 1 deletion src/semantic_version.cr
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SemanticVersion
struct Prerelease
def self.parse(str : String) : self
identifiers = [] of String | Int32
str.split(".").each do |val|
str.split('.').each do |val|
if val.match /^\d+$/
identifiers << val.to_i32
else
Expand Down

0 comments on commit 6c40696

Please sign in to comment.