'The algorithm works as follows:
Equal:
- Assure that the start is a newline, otherwise parse until we get
one.
- Copy from parsed_until_line + 1 to max(i2 + 1)
- Make sure that the indentation is correct (e.g. add DEDENT)
- Add old and change positions
Insert:
- Parse from parsed_until_line + 1 to min(j2 + 1), hopefully not
much more.
Returns the new module node.'

def update(self, old_lines, new_lines):

    debug.speed('diff    parser    start')
    self._module._used_names = None
    self._parser_lines_new = new_lines
    self._added_newline = False
    if (new_lines[(-1)] != ''):
        self._parser_lines_new = list(new_lines)
        self._parser_lines_new[(-1)] += '\n'
        self._parser_lines_new.append('')
        self._added_newline = True
    self._reset()
    line_length = len(new_lines)
    sm = difflib.SequenceMatcher(None, old_lines, self._parser_lines_new)
    opcodes = sm.get_opcodes()
    debug.speed('diff    parser    calculated')
    debug.dbg(('diff:    line_lengths    old:    %s,    new:    %s' % (len(old_lines), line_length)))
    for (operation, i1, i2, j1, j2) in opcodes:
        debug.dbg('diff    %s    old[%s:%s]    new[%s:%s]', operation, (i1 + 1), i2, (j1 + 1), j2)
        if (j2 == (line_length + int(self._added_newline))):
            j2 -= 1
        if (operation == 'equal'):
            line_offset = (j1 - i1)
            self._copy_from_old_parser(line_offset, i2, j2)
        elif (operation == 'replace'):
            self._parse(until_line=j2)
        elif (operation == 'insert'):
            self._parse(until_line=j2)
        else:
            assert (operation == 'delete')
    self._nodes_stack.close()
    if self._added_newline:
        _remove_last_newline(self._module)
    if debug.debug_function:
        self._enabled_debugging(old_lines, new_lines)
    last_pos = self._module.end_pos[0]
    if (last_pos != line_length):
        current_lines = splitlines(self._module.get_code(), keepends=True)
        diff = difflib.unified_diff(current_lines, new_lines)
        raise Exception(("There's    an    issue    (%s    !=    %s)    with    the    diff    parser.    Please    report:\n%s" % (last_pos, line_length, ''.join(diff))))
    debug.speed('diff    parser    end')
    return self._module
