Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: AndrewCot on March 19, 2022, 03:07:07 am

Title: Debuggergdb.cpp redundant code
Post by: AndrewCot on March 19, 2022, 03:07:07 am
In src\plugins\contrib-wip\debuggerGDB_MI\debuggergdb.cpp the OnTimer function is:
Code
void DebuggerGDB::OnTimer(cb_unused wxTimerEvent& event)
{
    // send any buffered (previous) output
    ParseOutput(wxEmptyString);

    CheckIfConsoleIsClosed();

    wxWakeUpIdle();
}
The ParseOutput function is:
Code
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
Code
ParseOutput(wxEmptyString);
is redundant. Have I missed something?
Title: Re: Debuggergdb.cpp redundant code
Post by: ollydbg on March 19, 2022, 03:31:55 am
From my point of view, you are correct.
Title: Re: Debuggergdb.cpp redundant code
Post by: Pecan on March 19, 2022, 06:01:55 am
That's just one of those laughable moments that make me think: "I hope I didn't do that!"
Title: Re: Debuggergdb.cpp redundant code
Post by: 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:

Code
        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
Code
cmd->ParseOutput(buffer);

Title: Re: Debuggergdb.cpp redundant code
Post by: ollydbg on March 20, 2022, 12:53:50 am
Another code snippet to check out, but this one will not slow things down as much as the previous one:

Code
        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
Code
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?
Title: Re: Debuggergdb.cpp redundant code
Post by: AndrewCot on March 20, 2022, 01:59:56 am
The
Code
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.
Title: Re: Debuggergdb.cpp redundant code
Post by: ollydbg on March 20, 2022, 02:34:53 am
The
Code
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!