Skip to content

Commit

Permalink
Revert "Revert "faster string() for ASCIIString. helps #2050""
Browse files Browse the repository at this point in the history
This reverts commit 57ad0dd.
  • Loading branch information
JeffBezanson committed Jul 2, 2013
1 parent f5a7c88 commit 4eb9f83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions base/ascii.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ getindex(s::ASCIIString, r::Range1{Int}) = ASCIIString(getindex(s.data,r))
getindex(s::ASCIIString, indx::AbstractVector{Int}) = ASCIIString(s.data[indx])
search(s::ASCIIString, c::Char, i::Integer) = c < 0x80 ? search(s.data,uint8(c),i) : 0
rsearch(s::ASCIIString, c::Char, i::Integer) = c < 0x80 ? rsearch(s.data,uint8(c),i) : 0
string(a::ASCIIString, b::ASCIIString, c::ASCIIString...) =
ASCIIString([a.data,b.data,map(s->s.data,c)...])

function string(c::ASCIIString...)
n = 0
for s in c
n += length(s.data)
end
v = Array(Uint8,n)
o = 1
for s in c
ls = length(s.data)
unsafe_copy!(v, o, s.data, 1, ls)
o += ls
end
ASCIIString(v)
end

function ucfirst(s::ASCIIString)
if 'a' <= s[1] <= 'z'
Expand Down
2 changes: 2 additions & 0 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ end
# all subtypes should implement this
write(s::IO, x::Uint8) = error(typeof(s)," does not support byte I/O")

write(io::IO, xs...) = for x in xs write(io, x) end

if ENDIAN_BOM == 0x01020304
function write(s::IO, x::Integer)
sz = sizeof(x)
Expand Down

0 comments on commit 4eb9f83

Please sign in to comment.