Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #23 from mariux64/improve-performance
Improve performance
  • Loading branch information
wwwutz committed Mar 22, 2019
2 parents fd01be5 + 1b83466 commit c9b7779
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 128 deletions.
117 changes: 35 additions & 82 deletions xdu.c
Expand Up @@ -88,12 +88,12 @@ int ncols = NCOLS;
* internal routines
*/
// char *strdup();
void addtree();
void parse_file();
void parse_entry();
static void addtree();
static void parse_file();
static void parse_entry();
void dumptree();
void clearrects();
void sorttree();
static void clearrects();
static void sorttree();

/*
* order to sort paths by
Expand Down Expand Up @@ -139,7 +139,7 @@ long nnodes = 0;
/*
* create a new node with the given name and size info
*/
struct node*
static struct node*
makenode(char* name, long long size)
{
struct node* np;
Expand All @@ -157,7 +157,7 @@ makenode(char* name, long long size)
* Return the node (if any) which has a draw rectangle containing
* the given x,y point.
*/
struct node*
static struct node*
findnode(struct node* treep, int x, int y)
{
struct node* np;
Expand Down Expand Up @@ -188,7 +188,7 @@ findnode(struct node* treep, int x, int y)
/*
* return a count of the number of children of a given node
*/
int numchildren(struct node* nodep)
static int numchildren(struct node* nodep)
{
int n;

Expand All @@ -207,7 +207,7 @@ int numchildren(struct node* nodep)
* had their sizes initialized. [DPT911113]
* * * * This function is recursive * * *
*/
long fix_tree(struct node* top)
static long fix_tree(struct node* top)
{
struct node* nd;

Expand Down Expand Up @@ -264,8 +264,8 @@ int main(int argc, char** argv)
/*
* dumptree(&top,0);
*/
if (order != ORD_DEFAULT)
sorttree(&top, order);

sorttree(&top, order);

topp = ⊤
/*
Expand All @@ -278,7 +278,7 @@ int main(int argc, char** argv)
exit(0);
}

void parse_file(char* filename)
static void parse_file(char* filename)
{
char buf[4096];
char name[4096];
Expand Down Expand Up @@ -317,7 +317,7 @@ void parse_file(char* filename)
/*
* bust up a path string and link it into the tree
*/
void parse_entry(char* name, long long size)
static void parse_entry(char* name, long long size)
{
char* path[MAXDEPTH]; /* break up path into this list */
char buf[MAXNAME]; /* temp space for path element
Expand Down Expand Up @@ -369,7 +369,7 @@ void parse_entry(char* name, long long size)
* 0 if it is a toss up.
* 1 if it should go after.
*/
int compare(struct node* n1, struct node* n2, int order)
static int compare(struct node* n1, struct node* n2, int order)
{
switch (order) {
case ORD_SIZE:
Expand Down Expand Up @@ -421,59 +421,10 @@ int compare(struct node* n1, struct node* n2, int order)
return 0;
}

void insertchild(struct node* nodep, struct node* childp, int order)
{
struct node *np,
*np1;

if (nodep == NODE_NULL || childp == NODE_NULL)
return;
if (childp->peer != NODE_NULL) {
fprintf(stderr, "xdu: can't insert child with peers\n");
return;
}

childp->parent = nodep;
if (nodep->child == NODE_NULL) {
/*
* no children, order doesn't matter
*/
nodep->child = childp;
return;
}
/*
* nodep has at least one child already
*/
if (compare(childp, nodep->child, order) < 0) {
/*
* new first child
*/
childp->peer = nodep->child;
nodep->child = childp;
return;
}
np1 = nodep->child;
for (np = np1->peer; np != NODE_NULL; np = np->peer) {
if (compare(childp, np, order) < 0) {
/*
* insert between np1 and np
*/
childp->peer = np;
np1->peer = childp;
return;
}
np1 = np;
}
/*
* at end, link new child on
*/
np1->peer = childp;
}

/*
* add path as a child of top - recursively
*/
void addtree(struct node* top, char* path[], long long size)
static void addtree(struct node* top, char* path[], long long size)
{
struct node* np;

Expand Down Expand Up @@ -507,7 +458,9 @@ void addtree(struct node* top, char* path[], long long size)
* no child matched, add a new child
*/
np = makenode(path[0], -1);
insertchild(top, np, order);
np->parent = top;
np->peer = top->child;
top->child=np;

if (path[1] == NULL) {
/*
Expand Down Expand Up @@ -540,7 +493,7 @@ void dumptree(struct node* np, int level)
}
}

void sorttree(struct node* np, int order)
static void sorttree(struct node* np, int order)
{
struct node* subnp;
struct node *np0,
Expand Down Expand Up @@ -588,7 +541,7 @@ void sorttree(struct node* np, int order)
* Draws all children of a node within the given rectangle.
* Recurses on children.
*/
void drawchildren(struct node* nodep, struct rect rect)
static void drawchildren(struct node* nodep, struct rect rect)
{
long long totalsize;
int totalheight;
Expand Down Expand Up @@ -665,7 +618,7 @@ void drawchildren(struct node* nodep, struct rect rect)
* Draws a node in the given rectangle, and all of its children
* to the "right" of the given rectangle.
*/
void drawnode(struct node* nodep, struct rect rect)
static void drawnode(struct node* nodep, struct rect rect)
{
struct rect subrect;

Expand Down Expand Up @@ -698,7 +651,7 @@ void drawnode(struct node* nodep, struct rect rect)
* clear the rectangle information of a given node
* and all of its decendents
*/
void clearrects(struct node* nodep)
static void clearrects(struct node* nodep)
{
struct node* np;

Expand All @@ -718,7 +671,7 @@ void clearrects(struct node* nodep)
}
}

void pwd(void)
static void pwd(void)
{
struct node* np;
struct node* stack[MAXDEPTH];
Expand Down Expand Up @@ -749,7 +702,7 @@ void pwd(void)
}

#ifdef NEED_STRDUP
char* strdup(char* s)
static char* strdup(char* s)
{
int n;
char* cp;
Expand Down Expand Up @@ -921,7 +874,7 @@ XDU Version %s - Keyboard Commands\n\
XDU_VERSION);
}

void fprintpsstart(FILE* fp)
static void fprintpsstart(FILE* fp)
{
fprintf(fp,
"%%!\n"
Expand All @@ -948,7 +901,7 @@ void fprintpsstart(FILE* fp)
"/xduorigctm matrix currentmatrix def\n\n");
}

void fprintpsend(FILE* fp)
static void fprintpsend(FILE* fp)
{
fprintf(fp,
"grestore\n"
Expand All @@ -961,7 +914,7 @@ void fprintpsend(FILE* fp)
"%%%%EOF\n");
}

void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
static void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
{
fprintf(fp,
"%%BOX\n"
Expand All @@ -979,7 +932,7 @@ void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
x1, y1, x2 + x1, y1, x2 + x1, y2 + y1, x1, y2 + y1);
}

void fprintpstext(FILE* fp, int x, int y, char* s)
static void fprintpstext(FILE* fp, int x, int y, char* s)
{
fprintf(fp,
"%%TEXT\n"
Expand All @@ -992,7 +945,7 @@ void fprintpstext(FILE* fp, int x, int y, char* s)
x, y, s);
}

void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize)
static void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize)
{
long long size, totalsize;
int totalheight,
Expand Down Expand Up @@ -1063,7 +1016,7 @@ void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize
}
}

void savepsnode(FILE* fp, struct node* nodep, struct rect rect, int showsize)
static void savepsnode(FILE* fp, struct node* nodep, struct rect rect, int showsize)
{
struct rect subrect;
char label[1024],
Expand Down Expand Up @@ -1128,24 +1081,24 @@ void savetops(char* fname, int showsize)
}
}

void fprintsvgstart(FILE* fp, int width, int height)
static void fprintsvgstart(FILE* fp, int width, int height)
{
fprintf(fp, "<?xml version=\"1.0\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"%d\" height=\"%d\">\n", width, height);
}

void fprintsvgend(FILE* fp)
static void fprintsvgend(FILE* fp)
{
fprintf(fp, "</svg>");
}

void fprintsvgnode(FILE* fp, struct rect rect)
static void fprintsvgnode(FILE* fp, struct rect rect)
{
fprintf(fp,
" <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" stroke=\"black\" stroke-width=\"1px\" fill=\"white\"/>\n",
rect.left, rect.top, rect.width, rect.height);
}

void fprintsvgnodetext(FILE* fp, int x, int y, long long size, char* name, int showsize)
static void fprintsvgnodetext(FILE* fp, int x, int y, long long size, char* name, int showsize)
{
char buffer[1024],
*text="n/a";
Expand Down Expand Up @@ -1182,7 +1135,7 @@ void fprintsvgnodetext(FILE* fp, int x, int y, long long size, char* name, int s
x, y, text);
}

void savesvgnode(FILE* fp, struct node* nodep, int showsize, int depth)
static void savesvgnode(FILE* fp, struct node* nodep, int showsize, int depth)
{
struct node* np;

Expand Down

0 comments on commit c9b7779

Please sign in to comment.