clean up FifoPlayerDlg::OnBeginSearch a bit

This commit is contained in:
Jordan Woyak 2013-01-08 14:41:58 -06:00
parent 815fd197d3
commit 00d303eead
1 changed files with 13 additions and 14 deletions

View File

@ -22,9 +22,13 @@
#include "FifoPlayer/FifoPlayer.h" #include "FifoPlayer/FifoPlayer.h"
#include "FifoPlayer/FifoRecorder.h" #include "FifoPlayer/FifoRecorder.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include <wx/spinctrl.h> #include <wx/spinctrl.h>
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
#include <algorithm>
#include <vector>
DECLARE_EVENT_TYPE(RECORDING_FINISHED_EVENT, -1) DECLARE_EVENT_TYPE(RECORDING_FINISHED_EVENT, -1)
DEFINE_EVENT_TYPE(RECORDING_FINISHED_EVENT) DEFINE_EVENT_TYPE(RECORDING_FINISHED_EVENT)
@ -440,26 +444,22 @@ void FifoPlayerDlg::OnBeginSearch(wxCommandEvent& event)
return; return;
} }
unsigned int val_length = str_search_val.Length() / 2; unsigned int const val_length = str_search_val.Length() / 2;
u8* search_val = new u8[val_length]; std::vector<u8> search_val(val_length);
for (unsigned int i = 0; i < val_length; ++i) for (unsigned int i = 0; i < val_length; ++i)
{ {
wxString char_str = str_search_val.Mid(2*i, 2); wxString char_str = str_search_val.Mid(2*i, 2);
unsigned long val; unsigned long val = 0;
if (!char_str.ToULong(&val, 16)) if (!char_str.ToULong(&val, 16))
{ {
m_numResultsText->SetLabel(_("Invalid search string (couldn't convert to number)")); m_numResultsText->SetLabel(_("Invalid search string (couldn't convert to number)"));
delete[] search_val;
return; return;
} }
search_val[i] = (u8)val; search_val[i] = (u8)val;
} }
search_results.clear(); search_results.clear();
u8* start_ptr; int const frame_idx = m_framesList->GetSelection();
u8* end_ptr;
int frame_idx = m_framesList->GetSelection();
FifoPlayer& player = FifoPlayer::GetInstance(); FifoPlayer& player = FifoPlayer::GetInstance();
const AnalyzedFrameInfo& frame = player.GetAnalyzedFrameInfo(frame_idx); const AnalyzedFrameInfo& frame = player.GetAnalyzedFrameInfo(frame_idx);
const FifoFrameInfo& fifo_frame = player.GetFile()->GetFrame(frame_idx); const FifoFrameInfo& fifo_frame = player.GetFile()->GetFrame(frame_idx);
@ -470,15 +470,15 @@ void FifoPlayerDlg::OnBeginSearch(wxCommandEvent& event)
if (obj_idx == -1) if (obj_idx == -1)
{ {
m_numResultsText->SetLabel(_("Invalid search parameters (no object selected)")); m_numResultsText->SetLabel(_("Invalid search parameters (no object selected)"));
delete[] search_val;
return; return;
} }
start_ptr = &fifo_frame.fifoData[frame.objectStarts[obj_idx]];
end_ptr = &fifo_frame.fifoData[frame.objectStarts[obj_idx+1]];
for (u8* ptr = start_ptr; ptr < end_ptr-val_length+1; ++ptr) const u8* const start_ptr = &fifo_frame.fifoData[frame.objectStarts[obj_idx]];
const u8* const end_ptr = &fifo_frame.fifoData[frame.objectStarts[obj_idx+1]];
for (const u8* ptr = start_ptr; ptr < end_ptr-val_length+1; ++ptr)
{ {
if (memcmp(ptr, search_val, val_length) == 0) if (std::equal(search_val.begin(), search_val.end(), ptr))
{ {
SearchResult result; SearchResult result;
result.frame_idx = frame_idx; result.frame_idx = frame_idx;
@ -497,7 +497,6 @@ void FifoPlayerDlg::OnBeginSearch(wxCommandEvent& event)
search_results.push_back(result); search_results.push_back(result);
} }
} }
delete[] search_val;
ChangeSearchResult(0); ChangeSearchResult(0);
m_beginSearch->Disable(); m_beginSearch->Disable();