parameters: (p)
return_statement: return ''.join(s)
docstring: Optimize a pickle string by removing unused PUT opcodes
docstring_summary: Optimize a pickle string by removing unused PUT opcodes
docstring_tokens: Optimize a pickle string by removing unused PUT opcodes
function: def optimize(p):
      'Optimize a pickle string by removing unused PUT opcodes'
      gets = set()            # set of args used by a GET opcode
      puts = []               # (arg, startpos, stoppos) for the PUT opcodes
      prevpos = None          # set to pos if previous opcode was a PUT
      for opcode, arg, pos in genops(p):
          if prevpos is not None:
              puts.append((prevarg, prevpos, pos))
              prevpos = None
          if 'PUT' in opcode.name:
              prevarg, prevpos = arg, pos
          elif 'GET' in opcode.name:
              gets.add(arg)
  
      # Copy the pickle string except for PUTS without a corresponding GET
      s = []
      i = 0
      for arg, start, stop in puts:
          j = stop if (arg in gets) else start
          s.append(p[i:j])
          i = stop
      s.append(p[i:])
      return ''.join(s)
function_tokens: def optimize ( p ) : gets = set ( ) # set of args used by a GET opcode puts = [ ] # (arg, startpos, stoppos) for the PUT opcodes prevpos = None # set to pos if previous opcode was a PUT for opcode , arg , pos in genops ( p ) : if prevpos is not None : puts . append ( ( prevarg , prevpos , pos ) ) prevpos = None if 'PUT' in opcode . name : prevarg , prevpos = arg , pos elif 'GET' in opcode . name : gets . add ( arg ) # Copy the pickle string except for PUTS without a corresponding GET s = [ ] i = 0 for arg , start , stop in puts : j = stop if ( arg in gets ) else start s . append ( p [ i : j ] ) i = stop s . append ( p [ i : ] ) return '' . join ( s )