Skip to content

RFC: deprecate RopeString #12330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,56 @@ function require_filename(name::AbstractString)
end
const reload = require
export reload

## ropes for efficient concatenation, etc. ##

immutable RopeString <: AbstractString
head::AbstractString
tail::AbstractString
depth::Int32
endof::Int

function _new(h, t, d, e)
depwarn("`RopeString` is deprecated, use `string` instead", :RopeString)
new(h, t, d, e)
end

RopeString(h::RopeString, t::RopeString) =
strdepth(h.tail) + strdepth(t) < strdepth(h.head) ?
RopeString(h.head, RopeString(h.tail, t)) :
_new(h, t, max(h.depth,t.depth)+1, endof(h)+endof(t))

RopeString(h::RopeString, t::AbstractString) =
strdepth(h.tail) < strdepth(h.head) ?
RopeString(h.head, RopeString(h.tail, t)) :
_new(h, t, h.depth+1, endof(h)+endof(t))

RopeString(h::AbstractString, t::RopeString) =
strdepth(t.head) < strdepth(t.tail) ?
RopeString(RopeString(h, t.head), t.tail) :
_new(h, t, t.depth+1, endof(h)+endof(t))

RopeString(h::AbstractString, t::AbstractString) =
_new(h, t, 1, endof(h)+endof(t))
end
RopeString(s::AbstractString) = RopeString(s,"")

strdepth(s::AbstractString) = 0
strdepth(s::RopeString) = s.depth

function next(s::RopeString, i::Int)
eh = endof(s.head)
if i <= eh
return next(s.head, i)
else
c, j = next(s.tail, i-eh)
return c, j+eh
end
end

endof(s::RopeString) = s.endof
length(s::RopeString) = length(s.head) + length(s.tail)
write(io::IO, s::RopeString) = (write(io, s.head); write(io, s.tail))
sizeof(s::RopeString) = sizeof(s.head) + sizeof(s.tail)

export RopeString
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export
RemoteRef,
RepString,
RevString,
RopeString,
RoundFromZero,
RoundDown,
RoundingMode,
Expand Down
46 changes: 0 additions & 46 deletions base/strings/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,49 +176,3 @@ function repeat(s::ByteString, r::Integer)
end

(^)(s::AbstractString, r::Integer) = repeat(s,r)

## ropes for efficient concatenation, etc. ##

immutable RopeString <: AbstractString
head::AbstractString
tail::AbstractString
depth::Int32
endof::Int

RopeString(h::RopeString, t::RopeString) =
strdepth(h.tail) + strdepth(t) < strdepth(h.head) ?
RopeString(h.head, RopeString(h.tail, t)) :
new(h, t, max(h.depth,t.depth)+1, endof(h)+endof(t))

RopeString(h::RopeString, t::AbstractString) =
strdepth(h.tail) < strdepth(h.head) ?
RopeString(h.head, RopeString(h.tail, t)) :
new(h, t, h.depth+1, endof(h)+endof(t))

RopeString(h::AbstractString, t::RopeString) =
strdepth(t.head) < strdepth(t.tail) ?
RopeString(RopeString(h, t.head), t.tail) :
new(h, t, t.depth+1, endof(h)+endof(t))

RopeString(h::AbstractString, t::AbstractString) =
new(h, t, 1, endof(h)+endof(t))
end
RopeString(s::AbstractString) = RopeString(s,"")

strdepth(s::AbstractString) = 0
strdepth(s::RopeString) = s.depth

function next(s::RopeString, i::Int)
eh = endof(s.head)
if i <= eh
return next(s.head, i)
else
c, j = next(s.tail, i-eh)
return c, j+eh
end
end

endof(s::RopeString) = s.endof
length(s::RopeString) = length(s.head) + length(s.tail)
write(io::IO, s::RopeString) = (write(io, s.head); write(io, s.tail))
sizeof(s::RopeString) = sizeof(s.head) + sizeof(s.tail)
4 changes: 0 additions & 4 deletions test/strings/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,3 @@ let
@test srep[7] == 'β'
@test_throws BoundsError srep[8]
end

## Rope strings ##

@test sizeof(RopeString("abc","def")) == 6