From 9337af921d97a6ff12ce428d2cdd7bf281025238 Mon Sep 17 00:00:00 2001 From: incastrix Date: Tue, 16 Sep 2008 01:06:46 +0000 Subject: [PATCH] Optimized net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread.getStackFrames() --- .../phpeclipse/xdebug/php/model/XDebugThread.java | 125 ++++++++++---------- 1 files changed, 61 insertions(+), 64 deletions(-) diff --git a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugThread.java b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugThread.java index fa29d34..91d1868 100644 --- a/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugThread.java +++ b/net.sourceforge.phpeclipse.xdebug.core/src/net/sourceforge/phpeclipse/xdebug/php/model/XDebugThread.java @@ -54,85 +54,82 @@ public class XDebugThread extends XDebugElement implements IThread, IDebugEventS public void incrementStepCounter() { fStepCount++; } - public IStackFrame[] getStackFrames() throws DebugException { - XDebugStackFrame[] newStackFrames = null; + if (!isSuspended()) { + return new IStackFrame[0]; + } - if (isSuspended()) { - if (fStepCount > fCurrentStepCount) { - //newStackFrames = ((XDebugTarget) getDebugTarget()).getStackFrames(); - - XDebugResponse dr = ((XDebugTarget) getDebugTarget()).getStackFrames(); - newStackFrames = _getStackFrames(dr); + if (fStepCount > fCurrentStepCount) { + XDebugResponse dr = ((XDebugTarget) getDebugTarget()).getStackFrames(); + XDebugStackFrame[] newStackFrames = _getStackFrames(dr); - for (int i = 0; i < newStackFrames.length; i++) { - newStackFrames[i].getVariables(); - } - - if (fStackFrames != null) { - if (newStackFrames.length >= fStackFrames.length) { - int delta = newStackFrames.length - fStackFrames.length + 1; - - for (int i = fStackFrames.length - 1; i >= 0; i--) { - if (fStackFrames[i].equals(newStackFrames[newStackFrames.length - delta])) { - int b = 2; b++; - //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]); - } else if (fStackFrames[i].isSameStackFrame(newStackFrames[newStackFrames.length - delta])) { - int b = 2; b++; - //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]); - } - - delta ++; + /*if (fStackFrames != null) { + if (newStackFrames.length >= fStackFrames.length) { + int delta = newStackFrames.length - fStackFrames.length + 1; + + for (int i = fStackFrames.length - 1; i >= 0; i--) { + if (fStackFrames[i].equals(newStackFrames[newStackFrames.length - delta])) { + int b = 2; b++; + //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]); + } else if (fStackFrames[i].isSameStackFrame(newStackFrames[newStackFrames.length - delta])) { + int b = 2; b++; + //((XDebugStackFrame) newStackFrames[newStackFrames.length - delta]).evaluateChange((XDebugStackFrame) fStackFrames[i]); } - } else { + + delta ++; } + } else { + fStackFrames = newStackFrames; } + } else { + fStackFrames = newStackFrames; + }*/ - fCurrentStepCount++; + fCurrentStepCount++; - fStackFrames = newStackFrames; - } - return fStackFrames; - } else { - return new IStackFrame[0]; + fStackFrames = newStackFrames; } + + return fStackFrames; } + private XDebugStackFrame[] _getStackFrames(XDebugResponse lastResponse) { - //IStackFrame[] newStackFrames = null; - - if (lastResponse.isError()) - return new XDebugStackFrame[0]; - Node response = lastResponse.getParentNode(); - NodeList frames = response.getChildNodes(); - XDebugStackFrame[] theFrames = new XDebugStackFrame[frames.getLength()]; - for (int i = 0; i < frames.getLength(); i++) { - Node stackNode = frames.item(i); - XDebugStackFrame frame = new XDebugStackFrame(this/*fThread*/, i); - String level =PHPDebugUtils.getAttributeValue(stackNode,"level"); - if (!"".equals(level)) - frame.setLevel(Integer.parseInt(level)); - - frame.setType(PHPDebugUtils.getAttributeValue(stackNode,"type")); - String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename")); - String lineNo=PHPDebugUtils.getAttributeValue(stackNode,"lineno"); - - if (!"".equals(lineNo)) - frame.setLineNumber(Integer.parseInt(lineNo)); - - frame.setWhere(PHPDebugUtils.getAttributeValue(stackNode,"where")); - - try { - frame.setFullName(new URL(fileName)); - } catch (MalformedURLException e) { - e.printStackTrace(); + if (lastResponse.isError()) { + return new XDebugStackFrame[0]; } + + Node response = lastResponse.getParentNode(); + NodeList frames = response.getChildNodes(); + XDebugStackFrame[] theFrames = new XDebugStackFrame[frames.getLength()]; + for (int i = 0; i < frames.getLength(); i++) { + Node stackNode = frames.item(i); + XDebugStackFrame frame = new XDebugStackFrame(this/*fThread*/, i); + String level =PHPDebugUtils.getAttributeValue(stackNode,"level"); + if (!"".equals(level)) + frame.setLevel(Integer.parseInt(level)); + + frame.setType(PHPDebugUtils.getAttributeValue(stackNode,"type")); + String fileName=PHPDebugUtils.unescapeString(PHPDebugUtils.getAttributeValue(stackNode,"filename")); + String lineNo=PHPDebugUtils.getAttributeValue(stackNode,"lineno"); - frame.incrementStepCounter(); + if (!"".equals(lineNo)) + frame.setLineNumber(Integer.parseInt(lineNo)); + + frame.setWhere(PHPDebugUtils.getAttributeValue(stackNode,"where")); + + try { + frame.setFullName(new URL(fileName)); + } catch (MalformedURLException e) { + e.printStackTrace(); + } - theFrames[i] = frame; - } - return /*newStackFrames*/theFrames; + frame.incrementStepCounter(); + + theFrames[i] = frame; + } + + return theFrames; } /* (non-Javadoc) -- 1.7.1