From 713fef5b08dfa10ce408053991fc4b45cc542c43 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Fri, 27 Jan 2006 19:21:16 +0000 Subject: [PATCH] Bug 107202: slow debug launch with external sources. Use "-p" option when passing a large number of directories to "cygpath". --- debug/org.eclipse.cdt.debug.mi.core/ChangeLog | 5 ++ .../mi/core/CygwinMIEnvironmentDirectory.java | 81 +++++++++++++++---- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index 35c66a58202..7ce133bdddd 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -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 diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinMIEnvironmentDirectory.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinMIEnvironmentDirectory.java index 69d49470401..f184ae81b73 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinMIEnvironmentDirectory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinMIEnvironmentDirectory.java @@ -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 index. + */ + 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; + } }