Skip to content

Commit 1038018

Browse files
author
José Valim
committed
Migrate from size to byte_size and tuple_size
1 parent 2b3e536 commit 1038018

File tree

10 files changed

+51
-51
lines changed

10 files changed

+51
-51
lines changed

lib/elixir/lib/io/ansi/docs.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ defmodule IO.ANSI.Docs do
192192
|> handle_links
193193
|> handle_inline(nil, [], [], options)
194194
|> String.split(~r{\s})
195-
|> write_with_wrap(options[:width] - size(indent), indent, from_list)
195+
|> write_with_wrap(options[:width] - byte_size(indent), indent, from_list)
196196

197197
unless from_list, do: IO.puts(IO.ANSI.reset)
198198
end

lib/elixir/lib/kernel.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ defmodule Kernel do
21442144
end
21452145

21462146
defp warn_info([entry|_]) do
2147-
opts = elem(entry, size(entry) - 1)
2147+
opts = elem(entry, tuple_size(entry) - 1)
21482148
Exception.format_file_line(Keyword.get(opts, :file), Keyword.get(opts, :line)) <> " "
21492149
end
21502150

lib/elixir/lib/module.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ defmodule Module do
797797
end
798798

799799
defp warn_info([entry|_]) do
800-
opts = elem(entry, size(entry) - 1)
800+
opts = elem(entry, tuple_size(entry) - 1)
801801
Exception.format_file_line(Keyword.get(opts, :file), Keyword.get(opts, :line)) <> " "
802802
end
803803

lib/elixir/lib/string.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,8 @@ defmodule String do
11831183
end
11841184

11851185
defp do_ends_with(string, suffix) when is_binary(suffix) do
1186-
string_size = size(string)
1187-
suffix_size = size(suffix)
1186+
string_size = byte_size(string)
1187+
suffix_size = byte_size(suffix)
11881188
scope = {string_size - suffix_size, suffix_size}
11891189
(suffix_size <= string_size) and (:nomatch != :binary.match(string, suffix, [scope: scope]))
11901190
end

lib/elixir/lib/string_io.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ defmodule StringIO do
199199
end
200200

201201
defp do_get_chars(input, :latin1, n) do
202-
<< chars :: [ binary, size(n) ], rest :: binary >> = input
202+
<<chars :: [binary, size(n)], rest :: binary>> = input
203203
{chars, rest}
204204
end
205205

@@ -209,7 +209,7 @@ defmodule StringIO do
209209
{buf_count, split_pos} when buf_count < n or split_pos == :none ->
210210
{input, ""}
211211
{_buf_count, split_pos} ->
212-
<< chars :: [ binary, size(split_pos) ], rest :: binary >> = input
212+
<<chars :: [binary, size(split_pos)], rest :: binary>> = input
213213
{chars, rest}
214214
end
215215
catch

lib/elixir/lib/uri.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ defmodule URI do
267267
# to replace those with nil for consistency.
268268
defp nillify(l) do
269269
for s <- l do
270-
if size(s) > 0, do: s, else: nil
270+
if byte_size(s) > 0, do: s, else: nil
271271
end
272272
end
273273
end

lib/elixir/test/elixir/kernel/binary_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bar """
4242
end
4343

4444
test :utf8 do
45-
assert size(" ゆんゆん") == 13
45+
assert byte_size(" ゆんゆん") == 13
4646
end
4747

4848
test :utf8_char do

lib/elixir/test/elixir/kernel/quote_test.exs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -348,63 +348,63 @@ end
348348
defmodule Kernel.QuoteTest.ImportsHygieneTest do
349349
use ExUnit.Case, async: true
350350

351-
defmacrop get_bin_size do
351+
defmacrop get_list_length do
352352
quote do
353-
size("hello")
353+
length('hello')
354354
end
355355
end
356356

357-
defmacrop get_bin_size_with_partial do
357+
defmacrop get_list_length_with_partial do
358358
quote do
359-
(&size(&1)).("hello")
359+
(&length(&1)).('hello')
360360
end
361361
end
362362

363-
defmacrop get_bin_size_with_function do
363+
defmacrop get_list_length_with_function do
364364
quote do
365-
(&size/1).("hello")
365+
(&length/1).('hello')
366366
end
367367
end
368368

369369
test :expand_imports do
370-
import Kernel, except: [size: 1]
371-
assert get_bin_size == 5
372-
assert get_bin_size_with_partial == 5
373-
assert get_bin_size_with_function == 5
370+
import Kernel, except: [length: 1]
371+
assert get_list_length == 5
372+
assert get_list_length_with_partial == 5
373+
assert get_list_length_with_function == 5
374374
end
375375

376-
defmacrop get_dict_size do
377-
import Kernel, except: [size: 1]
376+
defmacrop get_string_length do
377+
import Kernel, except: [length: 1]
378378

379379
quote do
380-
size([a: 1, b: 2])
380+
length("hello")
381381
end
382382
end
383383

384384
test :lazy_expand_imports do
385-
import Kernel, except: [size: 1]
386-
import Dict, only: [size: 1]
387-
assert get_dict_size == 2
385+
import Kernel, except: [length: 1]
386+
import String, only: [length: 1]
387+
assert get_string_length == 5
388388
end
389389

390390
test :lazy_expand_imports_no_conflicts do
391-
import Kernel, except: [size: 1]
392-
import Dict, only: [size: 1]
391+
import Kernel, except: [length: 1]
392+
import String, only: [length: 1]
393393

394-
assert get_bin_size == 5
395-
assert get_bin_size_with_partial == 5
396-
assert get_bin_size_with_function == 5
394+
assert get_list_length == 5
395+
assert get_list_length_with_partial == 5
396+
assert get_list_length_with_function == 5
397397
end
398398

399-
defmacrop with_size do
399+
defmacrop with_length do
400400
quote do
401-
import Kernel, except: [size: 1]
402-
import Dict, only: [size: 1]
403-
size("foo")
401+
import Kernel, except: [length: 1]
402+
import String, only: [length: 1]
403+
length('hello')
404404
end
405405
end
406406

407407
test :explicitly_overridden_imports do
408-
assert with_size == 3
408+
assert with_length == 5
409409
end
410410
end

lib/elixir/unicode/unicode.ex

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule String.Unicode do
2121
_bidi_mirror, _unicode_1, _iso,
2222
upper, lower, title ] = :binary.split(line, ";", [:global])
2323

24-
title = :binary.part(title, 0, size(title) - 1)
24+
title = :binary.part(title, 0, byte_size(title) - 1)
2525

2626
cond do
2727
upper != "" or lower != "" or title != "" ->
@@ -215,35 +215,35 @@ defmodule String.Graphemes do
215215
# Break on control
216216
for codepoint <- cluster["CR"] ++ cluster["LF"] ++ cluster["Control"] do
217217
def next_grapheme(<< unquote(codepoint), rest :: binary >> = string) do
218-
{:binary.part(string, 0, unquote(size(codepoint))), rest}
218+
{:binary.part(string, 0, unquote(byte_size(codepoint))), rest}
219219
end
220220
end
221221

222222
# Break on Prepend*
223223
# for codepoint <- cluster["Prepend"] do
224224
# def next_grapheme(<< unquote(codepoint), rest :: binary >> = string) do
225-
# next_prepend(rest, string, unquote(size(codepoint)))
225+
# next_prepend(rest, string, unquote(byte_size(codepoint)))
226226
# end
227227
# end
228228

229229
# Handle Hangul L
230230
for codepoint <- cluster["L"] do
231231
def next_grapheme(<< unquote(codepoint), rest :: binary >> = string) do
232-
next_hangul_l(rest, string, unquote(size(codepoint)))
232+
next_hangul_l(rest, string, unquote(byte_size(codepoint)))
233233
end
234234
end
235235

236236
# Handle Hangul T
237237
for codepoint <- cluster["T"] do
238238
def next_grapheme(<< unquote(codepoint), rest :: binary >> = string) do
239-
next_hangul_t(rest, string, unquote(size(codepoint)))
239+
next_hangul_t(rest, string, unquote(byte_size(codepoint)))
240240
end
241241
end
242242

243243
# Handle Regional
244244
for codepoint <- cluster["Regional_Indicator"] do
245245
def next_grapheme(<< unquote(codepoint), rest :: binary >> = string) do
246-
next_regional(rest, string, unquote(size(codepoint)))
246+
next_regional(rest, string, unquote(byte_size(codepoint)))
247247
end
248248
end
249249

@@ -263,19 +263,19 @@ defmodule String.Graphemes do
263263
# Handle Hangul L
264264
for codepoint <- cluster["L"] do
265265
defp next_hangul_l(<< unquote(codepoint), rest :: binary >>, string, size) do
266-
next_hangul_l(rest, string, size + unquote(size(codepoint)))
266+
next_hangul_l(rest, string, size + unquote(byte_size(codepoint)))
267267
end
268268
end
269269

270270
for codepoint <- cluster["LV"] do
271271
defp next_hangul_l(<< unquote(codepoint), rest :: binary >>, string, size) do
272-
next_hangul_v(rest, string, size + unquote(size(codepoint)))
272+
next_hangul_v(rest, string, size + unquote(byte_size(codepoint)))
273273
end
274274
end
275275

276276
for codepoint <- cluster["LVT"] do
277277
defp next_hangul_l(<< unquote(codepoint), rest :: binary >>, string, size) do
278-
next_hangul_t(rest, string, size + unquote(size(codepoint)))
278+
next_hangul_t(rest, string, size + unquote(byte_size(codepoint)))
279279
end
280280
end
281281

@@ -286,7 +286,7 @@ defmodule String.Graphemes do
286286
# Handle Hangul V
287287
for codepoint <- cluster["V"] do
288288
defp next_hangul_v(<< unquote(codepoint), rest :: binary >>, string, size) do
289-
next_hangul_v(rest, string, size + unquote(size(codepoint)))
289+
next_hangul_v(rest, string, size + unquote(byte_size(codepoint)))
290290
end
291291
end
292292

@@ -297,7 +297,7 @@ defmodule String.Graphemes do
297297
# Handle Hangul T
298298
for codepoint <- cluster["T"] do
299299
defp next_hangul_t(<< unquote(codepoint), rest :: binary >>, string, size) do
300-
next_hangul_t(rest, string, size + unquote(size(codepoint)))
300+
next_hangul_t(rest, string, size + unquote(byte_size(codepoint)))
301301
end
302302
end
303303

@@ -308,7 +308,7 @@ defmodule String.Graphemes do
308308
# Handle regional
309309
for codepoint <- cluster["Regional_Indicator"] do
310310
defp next_regional(<< unquote(codepoint), rest :: binary >>, string, size) do
311-
next_regional(rest, string, size + unquote(size(codepoint)))
311+
next_regional(rest, string, size + unquote(byte_size(codepoint)))
312312
end
313313
end
314314

@@ -319,7 +319,7 @@ defmodule String.Graphemes do
319319
# Handle Extend+SpacingMark
320320
for codepoint <- cluster["Extend"] ++ cluster["SpacingMark"] do
321321
defp next_extend(<< unquote(codepoint), rest :: binary >>, string, size) do
322-
next_extend(rest, string, size + unquote(size(codepoint)))
322+
next_extend(rest, string, size + unquote(byte_size(codepoint)))
323323
end
324324
end
325325

@@ -330,7 +330,7 @@ defmodule String.Graphemes do
330330
# Handle Prepend
331331
# for codepoint <- cluster["Prepend"] do
332332
# defp next_prepend(<< unquote(codepoint), rest :: binary >>, string, size) do
333-
# next_prepend(rest, string, size + unquote(size(codepoint)))
333+
# next_prepend(rest, string, size + unquote(byte_size(codepoint)))
334334
# end
335335
# end
336336
#

lib/iex/lib/iex/autocomplete.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ defmodule IEx.Autocomplete do
250250
end
251251

252252
defp to_hint(%{kind: :module, name: name}, hint) do
253-
:binary.part(name, size(hint), size(name) - size(hint)) <> "."
253+
:binary.part(name, byte_size(hint), byte_size(name) - byte_size(hint)) <> "."
254254
end
255255

256256
defp to_hint(%{kind: :function, name: name}, hint) do
257-
:binary.part(name, size(hint), size(name) - size(hint))
257+
:binary.part(name, byte_size(hint), byte_size(name) - byte_size(hint))
258258
end
259259
end

0 commit comments

Comments
 (0)