mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Minor cleanup:
- Add comment explaining the structure of the stack. - Minor optimization: make stack tuple directly usable as part of return value for enter/exit events.
This commit is contained in:
		
							parent
							
								
									187b1d8260
								
							
						
					
					
						commit
						127ee1607f
					
				
					 1 changed files with 11 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -41,6 +41,12 @@ def __init__(self, logfn):
 | 
			
		|||
            self.cwd = self._info['current-directory']
 | 
			
		||||
        else:
 | 
			
		||||
            self.cwd = None
 | 
			
		||||
 | 
			
		||||
        # This mirrors the call stack of the profiled code as the log
 | 
			
		||||
        # is read back in.  It contains tuples of the form:
 | 
			
		||||
        #
 | 
			
		||||
        #   (file name, line number of function def, function name)
 | 
			
		||||
        #
 | 
			
		||||
        self._stack = []
 | 
			
		||||
        self._append = self._stack.append
 | 
			
		||||
        self._pop = self._stack.pop
 | 
			
		||||
| 
						 | 
				
			
			@ -99,15 +105,15 @@ def next(self, index=0):
 | 
			
		|||
 | 
			
		||||
            if what == WHAT_ENTER:
 | 
			
		||||
                filename, funcname = self._decode_location(fileno, lineno)
 | 
			
		||||
                self._append((filename, funcname, lineno))
 | 
			
		||||
                return what, (filename, lineno, funcname), tdelta
 | 
			
		||||
                t = (filename, lineno, funcname)
 | 
			
		||||
                self._append(t)
 | 
			
		||||
                return what, t, tdelta
 | 
			
		||||
 | 
			
		||||
            if what == WHAT_EXIT:
 | 
			
		||||
                filename, funcname, lineno = self._pop()
 | 
			
		||||
                return what, (filename, lineno, funcname), tdelta
 | 
			
		||||
                return what, self._pop(), tdelta
 | 
			
		||||
 | 
			
		||||
            if what == WHAT_LINENO:
 | 
			
		||||
                filename, funcname, firstlineno = self._stack[-1]
 | 
			
		||||
                filename, firstlineno, funcname = self._stack[-1]
 | 
			
		||||
                return what, (filename, lineno, funcname), tdelta
 | 
			
		||||
 | 
			
		||||
            if what == WHAT_DEFINE_FILE:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue