Skip to content

Commit

Permalink
Fixed FindClosestLine returns wrong line
Browse files Browse the repository at this point in the history
  • Loading branch information
dankmolot committed Jul 5, 2024
1 parent 6ec84c4 commit 68a17d5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.3
2.1.4
4 changes: 2 additions & 2 deletions source/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ void yue_openlibs(void* state);

using namespace MoonLoader;

std::unordered_map<int, int> ParseYueLines(std::string_view code) {
std::map<int, int> ParseYueLines(std::string_view code) {
static std::regex YUE_LINE_REGEX("--\\s*(\\d*)\\s*$", std::regex_constants::optimize);

std::unordered_map<int, int> line_map;
std::map<int, int> line_map;
Utils::Split(code, [&](std::string_view line, size_t num) {
std::cmatch match;
if (std::regex_search(line.data(), line.data() + line.size(), match, YUE_LINE_REGEX)) {
Expand Down
3 changes: 2 additions & 1 deletion source/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <string_view>
#include <optional>
Expand Down Expand Up @@ -35,7 +36,7 @@ namespace MoonLoader {
size_t update_date = 0;
Type type;

std::unordered_map<int, int> line_map;
std::map<int, int> line_map;
};

private:
Expand Down
3 changes: 2 additions & 1 deletion source/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <optional>
#include <memory>
#include <unordered_map>
#include <map>

#if IS_SERVERSIDE
#include <GarrysMod/FactoryLoader.hpp>
Expand Down Expand Up @@ -219,7 +220,7 @@ namespace MoonLoader::Utils {
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
}

inline std::optional<int> FindClosestLine(const std::unordered_map<int, int>& lines, int line) {
inline std::optional<int> FindClosestLine(const std::map<int, int>& lines, int line) {
int closest = -1;
for (auto& [key, value] : lines) {
if (key > line) break;
Expand Down

0 comments on commit 68a17d5

Please sign in to comment.