1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 107202: slow debug launch with external sources. Use "-p" option when passing a large number of directories to "cygpath".

This commit is contained in:
Mikhail Khodjaiants 2006-01-27 19:21:16 +00:00
parent 4e635ba7cd
commit 713fef5b08
2 changed files with 71 additions and 15 deletions

View file

@ -1,3 +1,8 @@
2006-01-27 Mikhail Khodjaiants
Bug 107202: slow debug launch with external sources.
Use "-p" option when passing a large number of directories to "cygpath".
* CygwinMIEnvironmentDirectory.java
2006-01-25 Mikhail Khodjaiants
Reversing changes made to fix bug 107571. The fix for bug 119683 covers this problem too.
* mi/org/eclipse/cdt/debug/mi/core/MISession.java

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.debug.mi.core;
import java.io.ByteArrayOutputStream;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory;
@ -23,26 +24,76 @@ import org.eclipse.core.runtime.Path;
*/
public class CygwinMIEnvironmentDirectory extends MIEnvironmentDirectory {
final static private int BUFFER_SIZE = 1000;
/**
* To prevent to call "cygpath" for each folder (see //bugs.eclipse.org/bugs/show_bug.cgi?id=107202)
* we use the "-p" option of "cygpath".
* We can not convert the whole path in one shot because the size of the spawner's buffer is limited to 2049,
* so we divide the path's folders into groups.
*/
CygwinMIEnvironmentDirectory(String miVersion, boolean reset, String[] paths) {
super(miVersion, reset, paths);
String[] newpaths = new String[paths.length];
for (int i = 0; i < paths.length; i++) {
// Use the cygpath utility to convert the path
CommandLauncher launcher = new CommandLauncher();
ByteArrayOutputStream out = new ByteArrayOutputStream();
launcher.execute(
new Path("cygpath"), //$NON-NLS-1$
new String[] { "-u", paths[i] }, //$NON-NLS-1$
new String[0],
new Path(".")); //$NON-NLS-1$
if (launcher.waitAndRead(out, out) != CommandLauncher.OK)
newpaths[i] = paths[i];
else
newpaths[i] = out.toString().trim();
int index = 0;
while(index < paths.length) {
int length = 0;
StringBuffer sb = new StringBuffer(BUFFER_SIZE);
for (int i = index; i < paths.length; i++) {
if (length + paths[i].length() < BUFFER_SIZE) {
length += paths[i].length();
newpaths[i] = paths[i];
sb.append(paths[i]).append(';');
++length;
}
else {
convertPath(sb, newpaths, index);
index = i;
break;
}
if (i == paths.length - 1) {
convertPath(sb, newpaths, index);
index = paths.length;
break;
}
}
}
setParameters(newpaths);
}
/**
* Converts a path to the cygwin path and stores the resulting
* folders into the given array starting from <code>index</code>.
*/
private void convertPath(StringBuffer sb, String[] paths, int index) {
if (sb.charAt(sb.length() - 1) == ';')
sb.deleteCharAt(sb.length() - 1);
String result = convertPath0(sb.toString());
StringTokenizer st = new StringTokenizer(result, ":"); //$NON-NLS-1$
int j = index;
while(st.hasMoreTokens()) {
if (j >= paths.length)
break;
paths[j++] = st.nextToken();
}
}
/**
* Converts a windows type path into the cygwin type path using "cygpath"
* with the "-p" option.
*/
private String convertPath0(String path) {
String result = path;
CommandLauncher launcher = new CommandLauncher();
ByteArrayOutputStream out = new ByteArrayOutputStream();
launcher.execute(
new Path("cygpath"), //$NON-NLS-1$
new String[] { "-p", "-u", path }, //$NON-NLS-1$ //$NON-NLS-2$
new String[0],
new Path(".")); //$NON-NLS-1$
if (launcher.waitAndRead(out, out) == CommandLauncher.OK)
result = out.toString().trim();
return result;
}
}