1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +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 2006-01-25 Mikhail Khodjaiants
Reversing changes made to fix bug 107571. The fix for bug 119683 covers this problem too. 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 * mi/org/eclipse/cdt/debug/mi/core/MISession.java

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.debug.mi.core; package org.eclipse.cdt.debug.mi.core;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.CommandLauncher; import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory; import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory;
@ -23,26 +24,76 @@ import org.eclipse.core.runtime.Path;
*/ */
public class CygwinMIEnvironmentDirectory extends MIEnvironmentDirectory { 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) { CygwinMIEnvironmentDirectory(String miVersion, boolean reset, String[] paths) {
super(miVersion, reset, paths); super(miVersion, reset, paths);
String[] newpaths = new String[paths.length]; String[] newpaths = new String[paths.length];
for (int i = 0; i < paths.length; i++) { int index = 0;
// Use the cygpath utility to convert the path while(index < paths.length) {
CommandLauncher launcher = new CommandLauncher(); int length = 0;
ByteArrayOutputStream out = new ByteArrayOutputStream(); StringBuffer sb = new StringBuffer(BUFFER_SIZE);
for (int i = index; i < paths.length; i++) {
launcher.execute( if (length + paths[i].length() < BUFFER_SIZE) {
new Path("cygpath"), //$NON-NLS-1$ length += paths[i].length();
new String[] { "-u", paths[i] }, //$NON-NLS-1$ newpaths[i] = paths[i];
new String[0], sb.append(paths[i]).append(';');
new Path(".")); //$NON-NLS-1$ ++length;
if (launcher.waitAndRead(out, out) != CommandLauncher.OK) }
newpaths[i] = paths[i]; else {
else convertPath(sb, newpaths, index);
newpaths[i] = out.toString().trim(); index = i;
break;
}
if (i == paths.length - 1) {
convertPath(sb, newpaths, index);
index = paths.length;
break;
}
}
} }
setParameters(newpaths); 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;
}
} }