Skip to content

Commit

Permalink
Rename unshift!/shift! to pushfront!/popfront!
Browse files Browse the repository at this point in the history
  • Loading branch information
c42f committed Dec 15, 2017
1 parent f06f33c commit d4d1585
Show file tree
Hide file tree
Showing 40 changed files with 115 additions and 109 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ Deprecated or removed

* `Associative` has been deprecated in favor of `AbstractDict` ([#25012]).

* `unshift!` and `shift!` have been renamed to `pushfront!` and `popfront!`

Command-line option changes
---------------------------

Expand Down
6 changes: 3 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1992,12 +1992,12 @@ map!(f::F, dest::AbstractArray, As::AbstractArray...) where {F} = map_n!(f, dest
map(f) = f()
map(f, iters...) = collect(Generator(f, iters...))

# multi-item push!, unshift! (built on top of type-specific 1-item version)
# multi-item push!, pushfront! (built on top of type-specific 1-item version)
# (note: must not cause a dispatch loop when 1-item case is not defined)
push!(A, a, b) = push!(push!(A, a), b)
push!(A, a, b, c...) = push!(push!(A, a, b), c...)
unshift!(A, a, b) = unshift!(unshift!(A, b), a)
unshift!(A, a, b, c...) = unshift!(unshift!(A, c...), a, b)
pushfront!(A, a, b) = pushfront!(pushfront!(A, b), a)
pushfront!(A, a, b, c...) = pushfront!(pushfront!(A, c...), a, b)

## hashing collections ##

Expand Down
16 changes: 8 additions & 8 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ function prepend!(a::Array{<:Any,1}, items::AbstractVector)
end

prepend!(a::Vector, iter) = _prepend!(a, iteratorsize(iter), iter)
unshift!(a::Vector, iter...) = prepend!(a, iter)
pushfront!(a::Vector, iter...) = prepend!(a, iter)

function _prepend!(a, ::Union{HasLength,HasShape}, iter)
n = length(iter)
Expand All @@ -868,7 +868,7 @@ function _prepend!(a, ::IteratorSize, iter)
n = 0
for item in iter
n += 1
unshift!(a, item)
pushfront!(a, item)
end
reverse!(a, 1, n)
a
Expand Down Expand Up @@ -974,13 +974,13 @@ function pop!(a::Vector)
end

"""
unshift!(collection, items...) -> collection
pushfront!(collection, items...) -> collection
Insert one or more `items` at the beginning of `collection`.
# Examples
```jldoctest
julia> unshift!([1, 2, 3, 4], 5, 6)
julia> pushfront!([1, 2, 3, 4], 5, 6)
6-element Array{Int64,1}:
5
6
Expand All @@ -990,15 +990,15 @@ julia> unshift!([1, 2, 3, 4], 5, 6)
4
```
"""
function unshift!(a::Array{T,1}, item) where T
function pushfront!(a::Array{T,1}, item) where T
item = convert(T, item)
_growbeg!(a, 1)
a[1] = item
return a
end

"""
shift!(collection) -> item
popfront!(collection) -> item
Remove the first `item` from `collection`.
Expand All @@ -1013,7 +1013,7 @@ julia> A = [1, 2, 3, 4, 5, 6]
5
6
julia> shift!(A)
julia> popfront!(A)
1
julia> A
Expand All @@ -1025,7 +1025,7 @@ julia> A
6
```
"""
function shift!(a::Vector)
function popfront!(a::Vector)
if isempty(a)
throw(ArgumentError("array must be non-empty"))
end
Expand Down
4 changes: 2 additions & 2 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ function pop!(B::BitVector)
return item
end

function unshift!(B::BitVector, item)
function pushfront!(B::BitVector, item)
item = convert(Bool, item)

Bc = B.chunks
Expand All @@ -840,7 +840,7 @@ function unshift!(B::BitVector, item)
return B
end

function shift!(B::BitVector)
function popfront!(B::BitVector)
isempty(B) && throw(ArgumentError("argument must not be empty"))
@inbounds begin
item = B[1]
Expand Down
2 changes: 1 addition & 1 deletion base/bitset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end
end
@inline _delete!(s::BitSet, n::Integer) = _setint!(s, n, false)
@inline delete!(s::BitSet, n::Integer) = n > 0 ? _delete!(s, n) : s
shift!(s::BitSet) = pop!(s, first(s))
popfront!(s::BitSet) = pop!(s, first(s))

empty!(s::BitSet) = (fill!(s.bits, false); s)
isempty(s::BitSet) = !any(s.bits)
Expand Down
10 changes: 5 additions & 5 deletions base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function put_unbuffered(c::Channel, v)
rethrow(ex)
end
end
taker = shift!(c.takers)
taker = popfront!(c.takers)
yield(taker, v) # immediately give taker a chance to run, but don't block the current task
return v
end
Expand Down Expand Up @@ -318,23 +318,23 @@ task.
take!(c::Channel) = isbuffered(c) ? take_buffered(c) : take_unbuffered(c)
function take_buffered(c::Channel)
wait(c)
v = shift!(c.data)
v = popfront!(c.data)
notify(c.cond_put, nothing, false, false) # notify only one, since only one slot has become available for a put!.
v
end

shift!(c::Channel) = take!(c)
popfront!(c::Channel) = take!(c)

# 0-size channel
function take_unbuffered(c::Channel{T}) where T
check_channel_state(c)
push!(c.takers, current_task())
try
if length(c.putters) > 0
let refputter = Ref(shift!(c.putters))
let refputter = Ref(popfront!(c.putters))
return Base.try_yieldto(refputter) do putter
# if we fail to start putter, put it back in the queue
putter === current_task || unshift!(c.putters, putter)
putter === current_task || pushfront!(c.putters, putter)
end::T
end
else
Expand Down
4 changes: 2 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function process_options(opts::JLOptions)
end

# remove filename from ARGS
global PROGRAM_FILE = arg_is_program ? shift!(ARGS) : ""
global PROGRAM_FILE = arg_is_program ? popfront!(ARGS) : ""

# Load Distributed module only if any of the Distributed options have been specified.
if (opts.worker == 1) || (opts.nprocs > 0) || (opts.machinefile != C_NULL)
Expand Down Expand Up @@ -350,7 +350,7 @@ interactive sessions; this is useful to customize the interface. The argument of
REPL object. This function should be called from within the `.juliarc.jl` initialization
file.
"""
atreplinit(f::Function) = (unshift!(repl_hooks, f); nothing)
atreplinit(f::Function) = (pushfront!(repl_hooks, f); nothing)

function __atreplinit(repl)
for f in repl_hooks
Expand Down
6 changes: 5 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ function produce(v)
empty = true
break
elseif isa(q,Condition) && !isempty(q.waitq)
t = shift!(q.waitq)
t = popfront!(q.waitq)
empty = isempty(q.waitq)
break
end
Expand Down Expand Up @@ -3241,6 +3241,10 @@ end
@deprecate indices(a) axes(a)
@deprecate indices(a, d) axes(a, d)

# issue #23902
@deprecate pushfront! pushfront!
@deprecate popfront! popfront!

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
4 changes: 2 additions & 2 deletions base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ function matchinds(needle, haystack; acronym = false)
lastc = '\0'
for (i, char) in enumerate(haystack)
isempty(chars) && break
while chars[1] == ' ' shift!(chars) end # skip spaces
while chars[1] == ' ' popfront!(chars) end # skip spaces
if Unicode.lowercase(char) == Unicode.lowercase(chars[1]) &&
(!acronym || !Unicode.isalpha(lastc))
push!(is, i)
shift!(chars)
popfront!(chars)
end
lastc = char
end
Expand Down
8 changes: 4 additions & 4 deletions base/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function notify(c::Condition, arg, all, error)
empty!(c.waitq)
elseif !isempty(c.waitq)
cnt = 1
t = shift!(c.waitq)
t = popfront!(c.waitq)
error ? schedule(t, arg, error=error) : schedule(t, arg)
end
cnt
Expand Down Expand Up @@ -223,7 +223,7 @@ function ensure_rescheduled(othertask::Task)
if ct !== othertask && othertask.state == :runnable
# we failed to yield to othertask
# return it to the head of the queue to be scheduled later
unshift!(Workqueue, othertask)
pushfront!(Workqueue, othertask)
othertask.state = :queued
end
if ct.state == :queued
Expand All @@ -238,14 +238,14 @@ function ensure_rescheduled(othertask::Task)
end

@noinline function poptask()
t = shift!(Workqueue)
t = popfront!(Workqueue)
if t.state != :queued
# assume this somehow got queued twice,
# probably broken now, but try discarding this switch and keep going
# can't throw here, because it's probably not the fault of the caller to wait
# and don't want to use print() here, because that may try to incur a task switch
ccall(:jl_safe_printf, Void, (Ptr{UInt8}, Int32...),
"\nWARNING: Workqueue inconsistency detected: shift!(Workqueue).state != :queued\n")
"\nWARNING: Workqueue inconsistency detected: popfront!(Workqueue).state != :queued\n")
return
end
t.state = :runnable
Expand Down
4 changes: 2 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ export
prepend!,
push!,
resize!,
shift!,
unshift!,
popfront!,
pushfront!,

# collections
all!,
Expand Down
2 changes: 1 addition & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function pushmeta!(ex::Expr, sym::Symbol, args::Any...)
push!(exargs[idx].args, tag)
else
body::Expr = inner.args[2]
unshift!(body.args, Expr(:meta, tag))
pushfront!(body.args, Expr(:meta, tag))
end
ex
end
Expand Down
34 changes: 17 additions & 17 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4481,14 +4481,14 @@ function invoke_NF(argexprs, @nospecialize(etype), atypes::Vector{Any}, sv::Opti
ex.typ = etype
ex.args = copy(argexprs)
invoke_texpr === nothing || insert!(stmts, 2, invoke_texpr)
invoke_fexpr === nothing || unshift!(stmts, invoke_fexpr)
invoke_fexpr === nothing || pushfront!(stmts, invoke_fexpr)

local ret_var, merge, invoke_ex, spec_hit
ret_var = add_slot!(sv.src, widenconst(etype), false)
merge = genlabel(sv)
invoke_ex = copy(ex)
invoke_ex.head = :invoke
unshift!(invoke_ex.args, nothing)
pushfront!(invoke_ex.args, nothing)
spec_hit = false

function splitunion(atypes::Vector{Any}, i::Int)
Expand Down Expand Up @@ -4519,8 +4519,8 @@ function invoke_NF(argexprs, @nospecialize(etype), atypes::Vector{Any}, sv::Opti
isa_var = newvar!(sv, Bool)
isa_ty = Expr(:call, GlobalRef(Core, :isa), aei, ty)
isa_ty.typ = Bool
unshift!(match, Expr(:gotoifnot, isa_var, after.label))
unshift!(match, Expr(:(=), isa_var, isa_ty))
pushfront!(match, Expr(:gotoifnot, isa_var, after.label))
pushfront!(match, Expr(:(=), isa_var, isa_ty))
append!(stmts, match)
push!(stmts, after)
else
Expand Down Expand Up @@ -4561,7 +4561,7 @@ function invoke_NF(argexprs, @nospecialize(etype), atypes::Vector{Any}, sv::Opti
cache_linfo === nothing && return NF
add_backedge!(cache_linfo, sv)
argexprs = copy(argexprs)
unshift!(argexprs, cache_linfo)
pushfront!(argexprs, cache_linfo)
ex = Expr(:invoke)
ex.args = argexprs
ex.typ = etype
Expand Down Expand Up @@ -4653,8 +4653,8 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
argexpr0 = argexprs[2]
atypes = atypes[4:end]
argexprs = argexprs[4:end]
unshift!(atypes, atype0)
unshift!(argexprs, argexpr0)
pushfront!(atypes, atype0)
pushfront!(argexprs, argexpr0)
f = isdefined(ft, :instance) ? ft.instance : nothing
elseif isa(f, IntrinsicFunction) || ft IntrinsicFunction ||
isa(f, Builtin) || ft Builtin
Expand Down Expand Up @@ -4872,7 +4872,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
aei = argexprs[i]
aeitype = argtype = widenconst(exprtype(aei, sv.src, sv.mod))
if i == 1 && !(invoke_texpr === nothing)
unshift!(prelude_stmts, invoke_texpr)
pushfront!(prelude_stmts, invoke_texpr)
end

# ok for argument to occur more than once if the actual argument
Expand All @@ -4899,15 +4899,15 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
if occ != 0
vnew = newvar!(sv, aeitype)
argexprs[i] = vnew
unshift!(prelude_stmts, Expr(:(=), vnew, aei))
pushfront!(prelude_stmts, Expr(:(=), vnew, aei))
stmts_free &= free
elseif !free && !isType(aeitype)
unshift!(prelude_stmts, aei)
pushfront!(prelude_stmts, aei)
stmts_free = false
end
end
end
invoke_fexpr === nothing || unshift!(prelude_stmts, invoke_fexpr)
invoke_fexpr === nothing || pushfront!(prelude_stmts, invoke_fexpr)

# re-number the SSAValues and copy their type-info to the new ast
ssavalue_types = src.ssavaluetypes
Expand Down Expand Up @@ -4972,7 +4972,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
retval = add_slot!(sv.src, rettype, false)
end
multiret = true
unshift!(a.args, retval)
pushfront!(a.args, retval)
a.head = :(=)
push!(stmts, GotoNode(retstmt.label))
end
Expand All @@ -4981,7 +4981,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector

if multiret
if lastexpr !== nothing
unshift!(lastexpr.args, retval)
pushfront!(lastexpr.args, retval)
lastexpr.head = :(=)
push!(stmts, lastexpr)
end
Expand Down Expand Up @@ -5010,7 +5010,7 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
if !do_coverage && all(inlining_ignore, stmts)
empty!(stmts)
elseif isa(stmts[1], LineNumberNode)
linenode = shift!(stmts)::LineNumberNode
linenode = popfront!(stmts)::LineNumberNode
line = linenode.line
isa(linenode.file, Symbol) && (file = linenode.file)
end
Expand All @@ -5022,15 +5022,15 @@ function inlineable(@nospecialize(f), @nospecialize(ft), e::Expr, atypes::Vector
# function inlined in it
mod = method.module
if mod === sv.mod
unshift!(stmts, Expr(:meta, :push_loc, file,
pushfront!(stmts, Expr(:meta, :push_loc, file,
method.name, line))
else
unshift!(stmts, Expr(:meta, :push_loc, file,
pushfront!(stmts, Expr(:meta, :push_loc, file,
method.name, line, mod))
end
push!(stmts, Expr(:meta, :pop_loc))
elseif !isempty(stmts)
unshift!(stmts, Expr(:meta, :push_loc, file,
pushfront!(stmts, Expr(:meta, :push_loc, file,
method.name, line))
if isa(stmts[end], LineNumberNode)
stmts[end] = Expr(:meta, :pop_loc)
Expand Down
2 changes: 1 addition & 1 deletion base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const atexit_hooks = []
Register a zero-argument function `f()` to be called at process exit. `atexit()` hooks are
called in last in first out (LIFO) order and run before object finalizers.
"""
atexit(f::Function) = (unshift!(atexit_hooks, f); nothing)
atexit(f::Function) = (pushfront!(atexit_hooks, f); nothing)

function _atexit()
for f in atexit_hooks
Expand Down
Loading

0 comments on commit d4d1585

Please sign in to comment.