News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Debuggergdb.cpp redundant code

Started by AndrewCot, March 19, 2022, 03:07:07 AM

Previous topic - Next topic

AndrewCot

In src\plugins\contrib-wip\debuggerGDB_MI\debuggergdb.cpp the OnTimer function is:void DebuggerGDB::OnTimer(cb_unused wxTimerEvent& event)
{
    // send any buffered (previous) output
    ParseOutput(wxEmptyString);

    CheckIfConsoleIsClosed();

    wxWakeUpIdle();
}

The ParseOutput function is:
void DebuggerGDB::ParseOutput(const wxString& output)
{
    if (!output.IsEmpty() && m_State.HasDriver())
    {
        m_State.GetDriver()->ParseOutput(output);
    }
}

So my conclusion is that the OnTimer line ParseOutput(wxEmptyString); is redundant. Have I missed something?

ollydbg

From my point of view, you are correct.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Pecan

That's just one of those laughable moments that make me think: "I hope I didn't do that!"

AndrewCot

Another code snippet to check out, but this one will not slow things down as much as the previous one:

        buffer.Remove(idx);
        // remove the '>>>>>>' part of the prompt (or whats left of it)
        int cnt = 6; // max 6 '>'
        while (!buffer.empty() && buffer.Last() == _T('>') && cnt--)
            buffer.RemoveLast();
        if (!buffer.empty() && buffer.Last() == _T('\n'))
            buffer.RemoveLast();
        cmd->ParseOutput(buffer.Left(idx));

Check the first line and then ask yourself why the last line is not cmd->ParseOutput(buffer);


ollydbg

Quote from: AndrewCot on March 19, 2022, 06:58:45 AM
Another code snippet to check out, but this one will not slow things down as much as the previous one:

        buffer.Remove(idx);
        // remove the '>>>>>>' part of the prompt (or whats left of it)
        int cnt = 6; // max 6 '>'
        while (!buffer.empty() && buffer.Last() == _T('>') && cnt--)
            buffer.RemoveLast();
        if (!buffer.empty() && buffer.Last() == _T('\n'))
            buffer.RemoveLast();
        cmd->ParseOutput(buffer.Left(idx));

Check the first line and then ask yourself why the last line is not cmd->ParseOutput(buffer);

The first line is: Removes all characters from the string starting at idx, but it just returned the modified buffer, so the buffer is not changed. Right?

The last line is: Removes all the characters after the idx, and pass to the ParseOutput function.

So, the first line did nothing?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

AndrewCot

The buffer.Remove(idx); removes the characters in the buffer, so it removed from the idx offset to the end.
The RemoveLast calls remove the '>' if they are there.

So the last line calling with only the Left idx characters is redundant as the first line removed the characters after idx.

ollydbg

Quote from: AndrewCot on March 20, 2022, 01:59:56 AM
The buffer.Remove(idx); removes the characters in the buffer, so it removed from the idx offset to the end.
The RemoveLast calls remove the '>' if they are there.

So the last line calling with only the Left idx characters is redundant as the first line removed the characters after idx.

OK, you are correct!
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.