use += and do some more mitigation of the alloc problem first

This commit is contained in:
tg 2011-11-25 23:58:04 +00:00
parent 5c1108c5fa
commit 0d2244da81
1 changed files with 12 additions and 9 deletions

View File

@ -1,5 +1,5 @@
# $Id$ # $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.67 2011/11/25 23:54:06 tg Exp $ # $MirOS: src/bin/mksh/dot.mkshrc,v 1.68 2011/11/25 23:58:04 tg Exp $
#- #-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 # Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
# Thorsten Glaser <tg@mirbsd.org> # Thorsten Glaser <tg@mirbsd.org>
@ -123,7 +123,7 @@ function popd {
while getopts ":0123456789lvn" d; do while getopts ":0123456789lvn" d; do
case $d { case $d {
(l|v|n) fa="$fa -$d" ;; (l|v|n) fa+=" -$d" ;;
(+*) n=2 (+*) n=2
break ;; break ;;
(*) print -u2 'Usage: popd [-lvn] [+<n>].' (*) print -u2 'Usage: popd [-lvn] [+<n>].'
@ -159,7 +159,7 @@ function pushd {
while getopts ":0123456789lvn" d; do while getopts ":0123456789lvn" d; do
case $d { case $d {
(l|v|n) fa="$fa -$d" ;; (l|v|n) fa+=" -$d" ;;
(+*) n=2 (+*) n=2
break ;; break ;;
(*) print -u2 'Usage: pushd [-lvn] [<dir>|+<n>].' (*) print -u2 'Usage: pushd [-lvn] [<dir>|+<n>].'
@ -220,7 +220,7 @@ function Lb64decode {
set +U set +U
local c s="$*" t= local c s="$*" t=
[[ -n $s ]] || { s=$(cat;print x); s=${s%x}; } [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
local -i i=0 n=${#s} p=0 v x local -i i=0 j=0 n=${#s} p=0 v x
local -i16 o local -i16 o
while (( i < n )); do while (( i < n )); do
@ -243,7 +243,10 @@ function Lb64decode {
p=0 p=0
;; ;;
} }
t=$t\\x${o#16#} t+=\\x${o#16#}
(( ++j & 4095 )) && continue
print -n $t
t=
done done
print -n $t print -n $t
(( u )) || set -U (( u )) || set -U
@ -269,14 +272,14 @@ function Lb64encode {
(( v |= j << 8 )) (( v |= j << 8 ))
(( j = i < n ? s[i++] : 0 )) (( j = i < n ? s[i++] : 0 ))
(( v |= j )) (( v |= j ))
t=$t${Lb64encode_code[v >> 18]}${Lb64encode_code[v >> 12 & 63]} t+=${Lb64encode_code[v >> 18]}${Lb64encode_code[v >> 12 & 63]}
c=${Lb64encode_code[v >> 6 & 63]} c=${Lb64encode_code[v >> 6 & 63]}
if (( i <= n )); then if (( i <= n )); then
t=$t$c${Lb64encode_code[v & 63]} t+=$c${Lb64encode_code[v & 63]}
elif (( i == n + 1 )); then elif (( i == n + 1 )); then
t=$t$c= t+=$c=
else else
t=$t== t+===
fi fi
if (( ${#t} == 76 || i >= n )); then if (( ${#t} == 76 || i >= n )); then
print $t print $t