From 83dab8dd365e890189c3608dd9aa4a0ad532bba0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 22 Jun 2018 16:56:57 -0400 Subject: [PATCH] DSPTool: Get rid of raw new and delete We can just use a vector of a vector, which also has the benefit of keeping the size accounted for as well, allowing us to get rid of a count parameter for CodesToHeader(). --- Source/DSPTool/DSPTool.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/Source/DSPTool/DSPTool.cpp b/Source/DSPTool/DSPTool.cpp index 1dcd6e2f63..04d18293ea 100644 --- a/Source/DSPTool/DSPTool.cpp +++ b/Source/DSPTool/DSPTool.cpp @@ -73,46 +73,46 @@ static std::string CodeToHeader(const std::vector& code, const std::string& return header; } -static std::string CodesToHeader(const std::vector* codes, - const std::vector* filenames, u32 num_codes) +static std::string CodesToHeader(const std::vector>& codes, + const std::vector& filenames) { std::vector> codes_padded; - std::size_t reserveSize = 0; - for (u32 i = 0; i < num_codes; i++) + std::size_t reserve_size = 0; + for (std::size_t i = 0; i < codes.size(); i++) { codes_padded.push_back(codes[i]); // Pad with nops to 32byte boundary - while (codes_padded.at(i).size() & 0x7f) - codes_padded.at(i).push_back(0); + while (codes_padded[i].size() & 0x7f) + codes_padded[i].push_back(0); - reserveSize += codes_padded.at(i).size(); + reserve_size += codes_padded[i].size(); } std::string header; - header.reserve(reserveSize * 4); - header.append(StringFromFormat("#define NUM_UCODES %u\n\n", num_codes)); + header.reserve(reserve_size * 4); + header.append(StringFromFormat("#define NUM_UCODES %zu\n\n", codes.size())); header.append("const char* UCODE_NAMES[NUM_UCODES] = {\n"); - for (u32 i = 0; i < num_codes; i++) + for (const std::string& in_filename : filenames) { std::string filename; - if (!SplitPath(filenames->at(i), nullptr, &filename, nullptr)) - filename = filenames->at(i); + if (!SplitPath(in_filename, nullptr, &filename, nullptr)) + filename = in_filename; header.append(StringFromFormat("\t\"%s\",\n", filename.c_str())); } header.append("};\n\n"); header.append("const unsigned short dsp_code[NUM_UCODES][0x1000] = {\n"); - for (u32 i = 0; i < num_codes; i++) + for (std::size_t i = 0; i < codes.size(); i++) { - if (codes[i].size() == 0) + if (codes[i].empty()) continue; header.append("\t{\n\t\t"); - for (u32 j = 0; j < codes_padded.at(i).size(); j++) + for (std::size_t j = 0; j < codes_padded[i].size(); j++) { if (j && ((j & 15) == 0)) header.append("\n\t\t"); - header.append(StringFromFormat("0x%04x, ", codes_padded.at(i).at(j))); + header.append(StringFromFormat("0x%04x, ", codes_padded[i][j])); } header.append("\n\t},\n"); } @@ -290,7 +290,7 @@ static bool PerformAssembly(const std::string& input_name, const std::string& ou return false; } - std::vector* codes = new std::vector[lines]; + std::vector> codes(lines); for (int i = 0; i < lines; i++) { @@ -313,10 +313,8 @@ static bool PerformAssembly(const std::string& input_name, const std::string& ou } } - const std::string header = CodesToHeader(codes, &files, lines); + const std::string header = CodesToHeader(codes, files); File::WriteStringToFile(header, output_header_name + ".h"); - - delete[] codes; } else {