[Rear-users] SF.net SVN: rear:[742] trunk/usr/share/rear/lib/columns-functions.sh

jhoekx at users.sourceforge.net jhoekx at users.sourceforge.net
Wed Nov 23 16:27:14 CET 2011


Revision: 742
          http://rear.svn.sourceforge.net/rear/?rev=742&view=rev
Author:   jhoekx
Date:     2011-11-23 15:27:14 +0000 (Wed, 23 Nov 2011)
Log Message:
-----------
layout: improve performance of column detection functions in human readable output by using bash constructs.

Modified Paths:
--------------
    trunk/usr/share/rear/lib/columns-functions.sh

Modified: trunk/usr/share/rear/lib/columns-functions.sh
===================================================================
--- trunk/usr/share/rear/lib/columns-functions.sh	2011-11-23 15:25:47 UTC (rev 741)
+++ trunk/usr/share/rear/lib/columns-functions.sh	2011-11-23 15:27:14 UTC (rev 742)
@@ -32,14 +32,14 @@
     local wasspace=""
     local len=${#line}
     local i=0
-    while [ $i -lt $len ] ;
+    while (( $i < $len )) ;
     do
         local char="${line:$i:1}"
-        if [ -n "$wasspace" ] && [ "$char" = " " ] ;then
-            if [ -n "$word" ] ; then
+        if [[ "$wasspace" ]] && [[ "$char" = " " ]] ;then
+            if [[ "$word" ]] ; then
                 # word complete, write to list
                 let start=$i-${#word}
-                word=$(echo "$word" | tr '[:upper:]' '[:lower:]')
+                word=${word,,}
 
                 columns="$columns${word%% }=$start;"
                 word=""
@@ -48,7 +48,7 @@
             word="${word}${char}"
         fi
 
-        if [ "$char" = " " ] ; then
+        if [[ "$char" = " " ]] ; then
             wasspace="yes"
         else
             wasspace=""
@@ -58,7 +58,7 @@
     done
     # last word
     let start=$i-${#word}
-    word=$(echo "$word" | tr '[:upper:]' '[:lower:]')
+    word=${word,,}
     columns="$columns${word%% }=$start;"
 
     #echo "c:$columns"
@@ -69,7 +69,7 @@
     local start=$(get_column_start "$1")
 
     local nextheader=$(get_next_header "$1")
-    if [ -z "$nextheader" ] ; then
+    if [[ -z "$nextheader" ]] ; then
         echo "255"
         return 0
     fi
@@ -86,7 +86,7 @@
         local header=${pair%=*}
         local hstart=${pair#*=}
 
-        if [ "$header" = "$1" ] ; then
+        if [[ "$header" = "$1" ]] ; then
             echo "$hstart"
             restore_separator
             return 0
@@ -105,7 +105,7 @@
         local header=${pair%=*}
         local hstart=${pair#*=}
 
-        if [ "$previous" = "$1" ] ; then
+        if [[ "$previous" = "$1" ]] ; then
             echo "$header"
             restore_separator
             return 0

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the rear-users mailing list