mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2003
Posts: 37
B
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Oct 2003
Posts: 37
Below is an alias I wrote to read a list of directories from a window and create the directory structure in an mdx treeview dialog. It also adds the data to a window so it can be referenced later to show the contents of the directory. I'm trying to speed things up but I'm out of ideas, anyone have any suggestions???

-eMpTy


Code:
 
alias MTloaddirs {
  var %blah = $ticks
  var %numlines = $line(@AG7-Data,0)
  var %j = 1
  var %title = $dialog(treetest).title
  while (%j <= %numlines) {
    var %i = 1
    var %line = $replace($line(@AG7-Data,%j),$chr(32),$chr(95)) , %treeline
    var %numtok = $numtok(%line,92)
    while (%i <= %numtok) {
      var %temp = $left(%line,$pos(%line,$chr(92),%i))
      var %temp2 = $left(%line,$pos(%line,$chr(92),$calc(%i - 1)))
      if (!$hget(MTlistview,%temp)) {
        hadd MTlistview %temp 2
        if ((%i != 1) && (%root != 1)) { 
          did -i treetest 1 1 cb root %root %treeline
          did -a treetest 1 + 2 3 0 0 0 $replace($gettok(%temp,$numtok(%temp,92),92),$chr(95),$chr(32))
          aline @AG7-Data2 $chr(9) %root %treeline $chr(9) %temp
        }
        else {
          did -i treetest 1 1 cb root
          did -a treetest 1 + 1 1 0 0 0 $replace($gettok(%temp,$numtok(%temp,92),92),$chr(95),$chr(32))
          aline @AG7-Data2 $chr(9) $+ %treeline $+ $chr(9) %temp
        }
        if (%i != 1) { hinc MTlistview %temp2 }
        else { inc %root } 
      }
      if (%i != 1) var %treeline = %treeline $calc($hget(MTlistview,%temp2) - 1)
      inc %i
    }
    inc %j
    dialog -t treetest %title LOADING ( $+ $int($calc(%j / %numlines * 100)) $+ % $+ )
  }
  dialog -t treetest %title
  echo -s $calc($ticks - %blah)
}
 

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
it would help if i could see the source dir format window data or at least a few line of it. Is it....
/foldername/foldername/
or
foldername/foldername
or
/foldername/foldername
This would help me see if there was any way to restructure the routine for faster speed.
Also Im not sure if %root is ment to be zero to being with or not, it could have been a set u used elsewhere, i didnt really look into it as with no source dir data its hard to follow the scripts order of execution.

heres some things that may speed it up slightly
var %temp = $left(%line,$pos(%line,$chr(92),%i))
replace with
var %temp = $gettok(%line,1-%i,92) $+ \
(this might not be any faster honestly, and only works if the source dir's were not in the format \foldername...., this might be your reason for using $left instead of $gettok, im not sure)

$gettok(%temp,$numtok(%temp,92),92)
replace with
$gettok(%temp,-1,92)
(this should be ok regardless of source dir format)

if (%i != 1) var %treeline = %treeline $calc($hget(MTlistview,%temp2) - 1)
replace with
if (%i != 1) %treeline = %treeline $calc($hget(MTlistview,%temp2) - 1)
the VAR statment isnt needed and can add 20% time to processing the result into the value

Try this, it may help...
dialog -t treetest %title LOADING ( $+ $int($calc(%j / %numlines * 100)) $+ % $+ )
replace with
%p = $int($calc(%j / %numlines * 100)
if (%p != %p.v) {
%p.v = %p
dialog -t treetest %title LOADING ( $+ %p.v $+ % $+ )
}
The above well only send a new percentage out when ever the percentage changes, i have found in every program i have ever written in any language, a huge overhead in loops is the nice little display your putting on telling how far along you are, dump it or minimize it, and its usally faster, even if your code is more, you well have to try it to see. I would dump it alltogether, just tell em to stand by!
on this one above remeber to define the %p & %p.v as VAR at the top of the script

And on defining VAR you should define the whole lot at the start outside any loop, and then just use the variable name, as i said above var produces a 20% overhead when assigning values to existing varaibles.

heres something to check on
/did -h hide id
now i dont know about mirc but i know other apps work alot faster if u hide the item your altering, then display it at the end. I havent done stuff all with dialogs so i cant tell you if this works or is even the right command to do it.

on a precoutionary note, i would change these $replaces from using $chr(95) to using the ? character since 95 _ is a legit foldername character, and shouldnt be used a a space holder, since THIS_FOLDER_NAME well become THIS FOLDER NAME and THIS FOLDER_NAME well also become THIS FOLDER NAME, ? is not a legal character in foldernames so is a good as any place holder

I might be able to look at reworking the way you build your data, but without source data as an example its a bit hard to follow whats ment to happen.

Joined: Oct 2003
Posts: 37
B
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Oct 2003
Posts: 37
Wow, thanks for all the great suggestions...I'm just now getting started on implementing them and testing to see what kind of performance boost I can get...

The source data is simple, I get lists of files sorted by folders, filter all the lines containing :\ (indicating directory info) and then go through each line to make sure each folder is created (since you may have a c:\blah without ever having just c:\)...

here's an example of the source data...

Code:
 
D:\Rob\Music\CD Covers\
D:\Rob\Music\Music Videos\
D:\Rob\Music\MusicMatch Music\2001\
D:\Rob\Music\MusicMatch Music\CD Italian\
D:\Rob\Music\MusicMatch Music\Heavier Things\
D:\Rob\Music\MusicMatch Music\Riverhead (Bonus Disc)\
D:\Rob\Music\MusicMatch Music\Riverhead\
D:\Rob\Music\MusicMatch Music\title\
 


Thanks again,
eMpTy

Joined: Oct 2003
Posts: 37
B
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Oct 2003
Posts: 37
All of the changes made small but incremental differences in speed. The huge difference was getting rid of the percent done message...that was like a 75% boost...I'm officially a moron...

Hiding the dialog control made no difference...

-eMpTy


Link Copied to Clipboard