Optimization of displaying file list with categories

parent a4d9644d
......@@ -151,13 +151,14 @@ static string[] toReversePolishNotation(string[] infixNotation) {
*/
string[string] calculateExpression(in string[] expr) {
validateExpression(expr);
string[] expression = expr.dup;
alias string[string] AssociativeArray;
AssociativeArray[] intermediateData;
if (1 == expression.length) {
expression = expression ~ ["u:"] ~ expression;
}
string[] RPN = toReversePolishNotation(expression);
foreach(ref el; RPN) {
if (el.etype == ET.CATEGORY) {
string category = getCatDirPath(el);//getVitisPath ~ el;//;
......@@ -168,16 +169,16 @@ string[string] calculateExpression(in string[] expr) {
}
}
string[][] arrayWithFileLists;
ET[] arrayWithElementTypes;
string[string] assArrayWithLinkLists;
foreach(el; RPN) {
arrayWithElementTypes ~= el.etype;
if (ET.CATEGORY == el.etype) {
auto symlinksInfo = getSymlinksInfo(el);
assArrayWithLinkLists = mixAssociativeArrays(assArrayWithLinkLists,
el.getSymlinksInfo);
arrayWithFileLists ~= el.getSymlinksInfo.values;
symlinksInfo);
arrayWithFileLists ~= symlinksInfo.values;
} else {
arrayWithFileLists ~= null;
}
......@@ -219,5 +220,6 @@ string[string] calculateExpression(in string[] expr) {
}
}
}
return resultLinks;
}
......@@ -137,7 +137,7 @@ void mainFn(string[] args) {
if (command == CE.e_show) {
showingOptions = extractShowingOptions(args);
getopt(args, config.passThrough, "open", &openingMode,
"run", &runningMode);
"run", &runningMode);
if (openingMode) openingOptions = extractOpeningOptions(args);
if (runningMode) runningOptions = extractRunningOptions(args);
} else if (command == CE.e_open) {
......@@ -263,6 +263,20 @@ void showFilesByExpression(string[] expression,
void showFilesByFileList(string[string] fileList,
MainOptions mainOptions,
ShowingOptions opts) {
string[] categoriesOfFile;
auto typeOfOutput = opts.noColors ? "simple" : "category_details";
void subfnPrintCategories() {
auto lastIndex = categoriesOfFile.length-1;
foreach(i, c; categoriesOfFile) {
typeOfOutput.tprint(`"`~c~`"`);
if (lastIndex != i) {
typeOfOutput.tprint(" ");
} else {
"simple".tprint("\n");
}
}
}
setColorStdout(!opts.noColors);
setColorStderr(!opts.noColors);
......@@ -275,7 +289,6 @@ void showFilesByFileList(string[string] fileList,
size_t[string] numbersOfRepeatedNames = groupByFilePathWithNumbers(files);
string[] filepaths, linkpaths;
sortBySortEnum(mainOptions.sortEnum, files, filepaths, linkpaths);
string[] printableLinkPaths, printableFilePaths;
ssize_t maxNumber;
if (!mainOptions.numbers.empty) {
......@@ -291,8 +304,12 @@ void showFilesByFileList(string[string] fileList,
}
for (ssize_t index; index < printableLinkPaths.length; index++) {
ssize_t i = index;
if (mainOptions.reverse) i = printableLinkPaths.length - 1 - index;
ssize_t i;
if (!mainOptions.reverse) {
i = index;
} else {
i = printableLinkPaths.length - 1 - index;
}
string linkPath = printableLinkPaths[i];
if (linkPath == "") continue;
auto linkName = linkPath.baseName;
......@@ -300,6 +317,10 @@ void showFilesByFileList(string[string] fileList,
auto noNumbers = opts.noNumbers;
auto machine = opts.machineOutput;
if (opts.categories) {
categoriesOfFile = getCategoriesOfFile(filePath);
}
auto numberOfRepeating = numbersOfRepeatedNames[linkPath];
printLinkNameLine(linkName, i+1, maxNumber, noNumbers,
machine, numberOfRepeating);
......@@ -307,7 +328,7 @@ void showFilesByFileList(string[string] fileList,
if (opts.ipaths) printNetPath(filePath);
if (opts.details) printDetails(filePath, opts.noColors);
if (opts.fragmentInfo) printFragmentInfo(filePath);
if (opts.categories) printCategories(filePath, opts.noColors);
if (opts.categories) subfnPrintCategories();
}
}
......@@ -578,19 +599,6 @@ private auto getFragmentData(string filepath) {
}
private void printCategories(string filepath, bool noColors) {
string[] categories = getCategoriesOfFile(filepath);
foreach(i, c; categories) {
string typeOfOutput = noColors ? "simple" : "category_details";
typeOfOutput.tprint(`"`~c~`"`);
if (categories.length-1 != i)
typeOfOutput.tprint(" ");
else
"simple".tprint("\n");
}
}
string makeHumanOrientedByteSize(ulong bytes) {
long getExponent(ulong x) {
if (x == 0) return 0;
......@@ -648,7 +656,7 @@ private string[] getCategoriesOfFile(string file) {
if (file.isSymlink) file = file.readLink;
else if (!file.startsWith('/')) file = pwd ~ "/" ~ file;
string[string] allLinks = moduleBase.getAllLinks();
string[string] allLinks = getAllLinksFromCache();
foreach(l, lf; allLinks) {
if (lf != file) continue;
......
......@@ -388,6 +388,22 @@ string[] getTopLevelCategoriesAndAliases(
return usercategories ~ autocategories;
}
// without autocategories and without aliases
string[] getNoAutoCategories(Flag!"fullPath" fullPath = No.fullPath) {
auto categories = amalthea.fs.getDirListRecurse(getVitisPath)
.filter!(a => !a.baseName.startsWith("__"))
.filter!(a => !a.directoryOfFilePath.startsWith("__"))
.filter!(a => !a.isSymlink)
.array;
if (!fullPath) {
size_t l = getVitisPath().length;
foreach(ref cat; categories) {
cat = cat[l .. $];
}
}
return categories;
}
string[] getAllCategoriesAndAliases(Flag!"fullPath" fullPath = No.fullPath) {
//exclude unnecessary catalogies for repeared files and service catalogies
auto categories = amalthea.fs.getDirListRecurse(getVitisPath)
......@@ -423,7 +439,14 @@ string[] getAliases(Flag!"fullPath" fullPath = No.fullPath) {
string[] getTopLevelAutoCategories(Flag!"fullPath" fullPath = No.fullPath) {
if (!getAutoCategoriesPath().exists) return null;
return amalthea.fs.getDirList(getAutoCategoriesPath);
auto autoCategories = amalthea.fs.getDirList(getAutoCategoriesPath);
if (!fullPath) {
size_t l = getVitisPath().length;
foreach(ref cat; autoCategories) {
cat = cat[l .. $];
}
}
return autoCategories;
}
string[] getAllAutoCategories(Flag!"fullPath" fullPath = Yes.fullPath) {
......@@ -560,6 +583,21 @@ string[string] getAllLinks() {
return allLinks;
}
string[string] getAllLinksFromCache() {
static bool firstFunctionCall = true;
static string[string] allLinks;
if (!firstFunctionCall) return allLinks;
string[] allTopCategories = getTopLevelCategories();
foreach(category; allTopCategories) {
auto temp = amalthea.fs.getSymlinksInfo(category); //recursively
foreach(k, v; temp) allLinks[k] = v;
}
firstFunctionCall = false;
return allLinks;
}
deprecated string[] findFilesInVitis(string file) {
string[] categories = getTopLevelCategories(No.fullPath);
......@@ -813,3 +851,21 @@ void printErrorMessage(string msg) {
stderr.writeln(" ", msg);
}
deprecated alias exceptionHandler = printErrorMessage;
debug class Timer {
import std.datetime.stopwatch, core.thread;
StopWatch sw;
this() {
sw = StopWatch(AutoStart.no);
}
void start() {
sw.start();
}
void finish(bool noprint = false) {
sw.stop();
writeln(sw.peek.total!"usecs", " microseconds");
sw.reset();
}
}
\ No newline at end of file
0.13~pre2
\ No newline at end of file
0.13~pre3
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment