Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6a33f5d8eba1
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 591f8ef030fe
Choose a head ref
  • 9 commits
  • 16 files changed
  • 1 contributor

Commits on Jan 12, 2017

  1. Remove outdated TODOS

    Sija authored and Ary Borenszweig committed Jan 12, 2017
    Copy the full SHA
    160d7a9 View commit details
  2. Mark String#gen_to_ macro as private

    Sija authored and Ary Borenszweig committed Jan 12, 2017
    Copy the full SHA
    19c72dd View commit details
  3. Mark Time#def_at macro as private

    Sija authored and Ary Borenszweig committed Jan 12, 2017
    Copy the full SHA
    2b9b5b2 View commit details
  4. Mark XML::Builder#call and YAML::Builder#emit macros as private

    Sija authored and Ary Borenszweig committed Jan 12, 2017
    Copy the full SHA
    6287a80 View commit details
  5. Use Enum#none? instead of direct comparison

    Sija authored and Ary Borenszweig committed Jan 12, 2017
    Copy the full SHA
    f0e41c8 View commit details
  6. Use question mark methods in several cases for brevity

    Sija authored and Ary Borenszweig committed Jan 12, 2017
    Copy the full SHA
    b552128 View commit details
  7. Uncomment Reference#pretty_print spec

    Sija authored and Ary Borenszweig committed Jan 12, 2017
    Copy the full SHA
    abeb3ec View commit details
  8. Replace explicit | Nil unions with question mark instead

    Sija authored and Ary Borenszweig committed Jan 12, 2017
    Copy the full SHA
    88322d4 View commit details
  9. Removed deprecated methods from Char

    Sija authored and Ary Borenszweig committed Jan 12, 2017
    Copy the full SHA
    591f8ef View commit details
Showing with 40 additions and 62 deletions.
  1. +4 −5 spec/std/reference_spec.cr
  2. +1 −4 src/base64.cr
  3. +0 −12 src/char.cr
  4. +1 −4 src/debug/dwarf/line_numbers.cr
  5. +1 −1 src/enum.cr
  6. +8 −8 src/json/any.cr
  7. +1 −1 src/json/mapping.cr
  8. +9 −9 src/regex.cr
  9. +1 −1 src/static_array.cr
  10. +4 −5 src/string.cr
  11. +1 −1 src/time.cr
  12. +2 −2 src/unicode/unicode.cr
  13. +1 −2 src/weak_ref.cr
  14. +4 −5 src/xml/builder.cr
  15. +1 −1 src/yaml/builder.cr
  16. +1 −1 src/yaml/mapping.cr
9 changes: 4 additions & 5 deletions spec/std/reference_spec.cr
Original file line number Diff line number Diff line change
@@ -106,9 +106,8 @@ describe "Reference" do
clone.y.should eq(original.y)
end

# TODO uncomment after 0.20.3
# it "pretty_print" do
# ReferenceSpec::TestClassBase.new.pretty_inspect.should match(/\A#<ReferenceSpec::TestClassBase:0x[0-9a-f]+>\Z/)
# ReferenceSpec::TestClass.new(42, "foo").pretty_inspect.should match(/\A#<ReferenceSpec::TestClass:0x[0-9a-f]+ @x=42, @y="foo">\Z/)
# end
it "pretty_print" do
ReferenceSpec::TestClassBase.new.pretty_inspect.should match(/\A#<ReferenceSpec::TestClassBase:0x[0-9a-f]+>\Z/)
ReferenceSpec::TestClass.new(42, "foo").pretty_inspect.should match(/\A#<ReferenceSpec::TestClass:0x[0-9a-f]+ @x=42, @y="foo">\Z/)
end
end
5 changes: 1 addition & 4 deletions src/base64.cr
Original file line number Diff line number Diff line change
@@ -274,10 +274,7 @@ module Base64
end
end

# TODO: uncomment if release 'private macro'
# private macro next_decoded_value
# :nodoc:
macro next_decoded_value
private macro next_decoded_value
sym = cstr.value
res = dt[sym]
cstr += 1
12 changes: 0 additions & 12 deletions src/char.cr
Original file line number Diff line number Diff line change
@@ -124,12 +124,6 @@ struct Char
ord < 128
end

# DEPRECATED: use `#ascii_number?` or `#number?`. This method will be removed after 0.20.0.
def digit?(base : Int = 10)
{{ puts "Warning: `Char#digit?` is deprecated and will be removed after 0.20.0, use `Char#ascii_number?` or `Char#number?` instead".id }}
ascii_number?(base)
end

# Returns `true` if this char is an ASCII number in specified base.
#
# Base can be from 0 to 36 with digits from '0' to '9' and 'a' to 'z' or 'A' to 'Z'.
@@ -201,12 +195,6 @@ struct Char
ascii? ? ascii_uppercase? : Unicode.uppercase?(self)
end

# DEPRECATED: use `#ascii_letter?` or `#letter?`. This method will be removed after 0.20.0.
def alpha?
{{ puts "Warning: `Char#alpha?` is deprecated and will be removed after 0.20.0, use `Char#ascii_letter?` or `Char#letter?` instead".id }}
ascii_letter?
end

# Returns `true` if this char is an ASCII letter ('a' to 'z', 'A' to 'Z').
#
# ```
5 changes: 1 addition & 4 deletions src/debug/dwarf/line_numbers.cr
Original file line number Diff line number Diff line change
@@ -261,10 +261,7 @@ module Debug
end
end

# TODO: uncomment if release 'private macro'
# private macro increment_address_and_op_index(operation_advance)
# :nodoc:
macro increment_address_and_op_index(operation_advance)
private macro increment_address_and_op_index(operation_advance)
if sequence.maximum_operations_per_instruction == 1
registers.address += {{operation_advance}} * sequence.minimum_instruction_length
else
2 changes: 1 addition & 1 deletion src/enum.cr
Original file line number Diff line number Diff line change
@@ -339,7 +339,7 @@ struct Enum
# Color.from_value?(2) # => Color::Blue
# Color.from_value?(3) # => nil
# ```
def self.from_value?(value) : self | Nil
def self.from_value?(value) : self?
{% if @type.has_attribute?("Flags") %}
mask = {% for member, i in @type.constants %}\
{% if i != 0 %} | {% end %}\
16 changes: 8 additions & 8 deletions src/json/any.cr
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ struct JSON::Any
end

# Checks that the underlying value is `Bool`, and returns its value. Returns nil otherwise.
def as_bool? : (Bool | Nil)
def as_bool? : Bool?
as_bool if @raw.is_a?(Bool)
end

@@ -156,7 +156,7 @@ struct JSON::Any
end

# Checks that the underlying value is `Int`, and returns its value as an `Int32`. Returns nil otherwise.
def as_i? : (Int32 | Nil)
def as_i? : Int32?
as_i if @raw.is_a?(Int)
end

@@ -166,7 +166,7 @@ struct JSON::Any
end

# Checks that the underlying value is `Int`, and returns its value as an `Int64`. Returns nil otherwise.
def as_i64? : (Int64 | Nil)
def as_i64? : Int64?
as_i64 if @raw.is_a?(Int64)
end

@@ -176,7 +176,7 @@ struct JSON::Any
end

# Checks that the underlying value is `Float`, and returns its value as an `Float64`. Returns nil otherwise.
def as_f? : (Float64 | Nil)
def as_f? : Float64?
as_f if @raw.is_a?(Float64)
end

@@ -186,7 +186,7 @@ struct JSON::Any
end

# Checks that the underlying value is `Float`, and returns its value as an `Float32`. Returns nil otherwise.
def as_f32? : (Float32 | Nil)
def as_f32? : Float32?
as_f32 if (@raw.is_a?(Float32) || @raw.is_a?(Float64))
end

@@ -196,7 +196,7 @@ struct JSON::Any
end

# Checks that the underlying value is `String`, and returns its value. Returns nil otherwise.
def as_s? : (String | Nil)
def as_s? : String?
as_s if @raw.is_a?(String)
end

@@ -206,7 +206,7 @@ struct JSON::Any
end

# Checks that the underlying value is `Array`, and returns its value. Returns nil otherwise.
def as_a? : (Array(Type) | Nil)
def as_a? : Array(Type)?
as_a if @raw.is_a?(Array(Type))
end

@@ -216,7 +216,7 @@ struct JSON::Any
end

# Checks that the underlying value is `Hash`, and returns its value. Returns nil otherwise.
def as_h? : (Hash(String, Type) | Nil)
def as_h? : Hash(String, Type)?
as_h if @raw.is_a?(Hash(String, Type))
end

2 changes: 1 addition & 1 deletion src/json/mapping.cr
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ module JSON
# The value can also be another hash literal with the following options:
# * **type**: (required) the single type described above (you can use `JSON::Any` too)
# * **key**: the property name in the JSON document (as opposed to the property name in the Crystal code)
# * **nilable**: if true, the property can be `Nil`. Passing `T | Nil` as a type has the same effect.
# * **nilable**: if true, the property can be `Nil`. Passing `T?` as a type has the same effect.
# * **default**: value to use if the property is missing in the JSON document, or if it's `null` and `nilable` was not set to `true`. If the default value creates a new instance of an object (for example `[1, 2, 3]` or `SomeObject.new`), a different instance will be used each time a JSON document is parsed.
# * **emit_null**: if true, emits a `null` value for nilable properties (by default nulls are not emitted)
# * **converter**: specify an alternate type for parsing and generation. The converter must define `from_json(JSON::PullParser)` and `to_json(value, JSON::Builder)` as class methods. Examples of converters are `Time::Format` and `Time::EpochConverter` for `Time`.
18 changes: 9 additions & 9 deletions src/regex.cr
Original file line number Diff line number Diff line change
@@ -395,9 +395,9 @@ class Regex
io << "/"
append_source(io)
io << "/"
io << "i" if options.includes?(Options::IGNORE_CASE)
io << "m" if options.includes?(Options::MULTILINE)
io << "x" if options.includes?(Options::EXTENDED)
io << "i" if options.ignore_case?
io << "m" if options.multiline?
io << "x" if options.extended?
end

# Match at character index. Matches a regular expression against String
@@ -490,14 +490,14 @@ class Regex
# ```
def to_s(io : IO)
io << "(?"
io << "i" if options.includes?(Options::IGNORE_CASE)
io << "ms" if options.includes?(Options::MULTILINE)
io << "x" if options.includes?(Options::EXTENDED)
io << "i" if options.ignore_case?
io << "ms" if options.multiline?
io << "x" if options.extended?

io << "-"
io << "i" unless options.includes?(Options::IGNORE_CASE)
io << "ms" unless options.includes?(Options::MULTILINE)
io << "x" unless options.includes?(Options::EXTENDED)
io << "i" unless options.ignore_case?
io << "ms" unless options.multiline?
io << "x" unless options.extended?

io << ":"
append_source(io)
2 changes: 1 addition & 1 deletion src/static_array.cr
Original file line number Diff line number Diff line change
@@ -214,7 +214,7 @@ struct StaticArray(T, N)
# Don't pass `self` here because we'll pass `self` by
# value and for big static arrays that seems to make
# LLVM really slow.
# # TODO: investigate why, maybe report a bug to LLVM?
# TODO: investigate why, maybe report a bug to LLVM?
pp.list("StaticArray[", to_slice, "]")
end

9 changes: 4 additions & 5 deletions src/string.cr
Original file line number Diff line number Diff line change
@@ -469,8 +469,7 @@ class String
negative : Bool,
invalid : Bool

# :nodoc:
macro gen_to_(method, max_positive = nil, max_negative = nil)
private macro gen_to_(method, max_positive = nil, max_negative = nil)
info = to_u64_info(base, whitespace, underscore, prefix, strict)
return yield if info.invalid

@@ -890,7 +889,7 @@ class String
def downcase(options = Unicode::CaseOptions::None)
return self if empty?

if ascii_only? && ((options == Unicode::CaseOptions::None) || options.ascii?)
if ascii_only? && (options.none? || options.ascii?)
String.new(bytesize) do |buffer|
bytesize.times do |i|
buffer[i] = to_unsafe[i].unsafe_chr.downcase.ord.to_u8
@@ -917,7 +916,7 @@ class String
def upcase(options = Unicode::CaseOptions::None)
return self if empty?

if ascii_only? && ((options == Unicode::CaseOptions::None) || options.ascii?)
if ascii_only? && (options.none? || options.ascii?)
String.new(bytesize) do |buffer|
bytesize.times do |i|
buffer[i] = to_unsafe[i].unsafe_chr.upcase.ord.to_u8
@@ -944,7 +943,7 @@ class String
def capitalize(options = Unicode::CaseOptions::None)
return self if empty?

if ascii_only? && ((options == Unicode::CaseOptions::None) || options.ascii?)
if ascii_only? && (options.none? || options.ascii?)
String.new(bytesize) do |buffer|
bytesize.times do |i|
if i == 0
2 changes: 1 addition & 1 deletion src/time.cr
Original file line number Diff line number Diff line change
@@ -410,7 +410,7 @@ struct Time
end
end

macro def_at(name)
private macro def_at(name)
def at_{{name.id}}
year, month, day, day_year = year_month_day_day_year
mask({{yield}})
4 changes: 2 additions & 2 deletions src/unicode/unicode.cr
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ module Unicode
end

private def self.check_upcase_ascii(char, options)
if (char.ascii? && options == Unicode::CaseOptions::None) || options.ascii?
if (char.ascii? && options.none?) || options.ascii?
if char.ascii_lowercase?
return (char.ord - 32).unsafe_chr
else
@@ -120,7 +120,7 @@ module Unicode
end

private def self.check_downcase_ascii(char, options)
if (char.ascii? && options == Unicode::CaseOptions::None) || options.ascii?
if (char.ascii? && options.none?) || options.ascii?
if char.ascii_uppercase?
return (char.ord + 32).unsafe_chr
else
3 changes: 1 addition & 2 deletions src/weak_ref.cr
Original file line number Diff line number Diff line change
@@ -10,8 +10,7 @@ class WeakRef(T)

def self.allocate
ptr = GC.malloc_atomic(sizeof(self)).as(self)
# TODO: uncomment after 0.20.1
# set_crystal_type_id(ptr)
set_crystal_type_id(ptr)
ptr
end

9 changes: 4 additions & 5 deletions src/xml/builder.cr
Original file line number Diff line number Diff line change
@@ -266,11 +266,10 @@ struct XML::Builder
call SetQuoteChar, char.ord
end

# TODO: mark as private
macro call(name, *args)
ret = LibXML.xmlTextWriter{{name}}(@writer, {{*args}})
check ret, {{@def.name.stringify}}
end
private macro call(name, *args)
ret = LibXML.xmlTextWriter{{name}}(@writer, {{*args}})
check ret, {{@def.name.stringify}}
end

private def check(ret, msg)
raise XML::Error.new("error in #{msg}", 0) if ret < 0
2 changes: 1 addition & 1 deletion src/yaml/builder.cr
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ class YAML::Builder
@closed = true
end

macro emit(event_name, *args)
private macro emit(event_name, *args)
LibYAML.yaml_{{event_name}}_event_initialize(pointerof(@event), {{*args}})
yaml_emit({{event_name.stringify}})
end
2 changes: 1 addition & 1 deletion src/yaml/mapping.cr
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ module YAML
# Available attributes:
#
# * *type* (required) defines its type. In the example above, *title: String* is a shortcut to *title: {type: String}*.
# * *nilable* defines if a property can be a `Nil`. Passing `T | Nil` as a type has the same effect.
# * *nilable* defines if a property can be a `Nil`. Passing `T?` as a type has the same effect.
# * **default**: value to use if the property is missing in the YAML document, or if it's `null` and `nilable` was not set to `true`. If the default value creates a new instance of an object (for example `[1, 2, 3]` or `SomeObject.new`), a different instance will be used each time a YAML document is parsed.
# * *key* defines which key to read from a YAML document. It defaults to the name of the property.
# * *converter* takes an alternate type for parsing. It requires a `#from_yaml` method in that class, and returns an instance of the given type. Examples of converters are `Time::Format` and `Time::EpochConverter` for `Time`.