From 60aa72e1177c436351c91be291ef869816df79e0 Mon Sep 17 00:00:00 2001
From: bunnei <bunneidev@gmail.com>
Date: Tue, 12 Apr 2016 23:24:34 -0400
Subject: [PATCH] shader_jit_x64: Use a sorted vector instead of a set for
 keeping track of return addresses.

---
 src/video_core/shader/shader_jit_x64.cpp | 9 ++++++---
 src/video_core/shader/shader_jit_x64.h   | 4 ++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cpp
index 503fad1586..e32a4e7204 100644
--- a/src/video_core/shader/shader_jit_x64.cpp
+++ b/src/video_core/shader/shader_jit_x64.cpp
@@ -2,6 +2,7 @@
 // Licensed under GPLv2 or any later version
 // Refer to the license.txt file included.
 
+#include <algorithm>
 #include <smmintrin.h>
 
 #include "common/x64/abi.h"
@@ -760,8 +761,7 @@ void JitCompiler::Compile_Return() {
 }
 
 void JitCompiler::Compile_NextInstr() {
-    auto search = return_offsets.find(program_counter);
-    if (search != return_offsets.end()) {
+    if (std::binary_search(return_offsets.begin(), return_offsets.end(), program_counter)) {
         Compile_Return();
     }
 
@@ -793,10 +793,13 @@ void JitCompiler::FindReturnOffsets() {
         case OpCode::Id::CALL:
         case OpCode::Id::CALLC:
         case OpCode::Id::CALLU:
-            return_offsets.insert(instr.flow_control.dest_offset + instr.flow_control.num_instructions);
+            return_offsets.push_back(instr.flow_control.dest_offset + instr.flow_control.num_instructions);
             break;
         }
     }
+
+    // Sort for efficient binary search later
+    std::sort(return_offsets.begin(), return_offsets.end());
 }
 
 void JitCompiler::Compile() {
diff --git a/src/video_core/shader/shader_jit_x64.h b/src/video_core/shader/shader_jit_x64.h
index 920a269e23..aa5060584d 100644
--- a/src/video_core/shader/shader_jit_x64.h
+++ b/src/video_core/shader/shader_jit_x64.h
@@ -4,8 +4,8 @@
 
 #pragma once
 
-#include <set>
 #include <utility>
+#include <vector>
 
 #include <nihstro/shader_bytecode.h>
 
@@ -106,7 +106,7 @@ private:
     std::array<const u8*, 1024> code_ptr;
 
     /// Offsets in code where a return needs to be inserted
-    std::set<unsigned> return_offsets;
+    std::vector<unsigned> return_offsets;
 
     unsigned program_counter = 0;       ///< Offset of the next instruction to decode
     bool looping = false;               ///< True if compiling a loop, used to check for nested loops