MCPcopy Create free account
hub / github.com/GJDuck/e9patch / lower_bound

Method lower_bound

src/e9patch/e9misc.cpp:105–123  ·  view source on GitHub ↗

* Find the first instruction >= the offset. */

Source from the content-addressed store, hash-verified

103 * Find the first instruction >= the offset.
104 */
105Instr *InstrSet::lower_bound(off_t offset) const
106{
107 if (lb == ub) return nullptr;
108 const Instr *Is = lb;
109 ssize_t lo = 0, hi = (ub - lb) - 1, mid = 0;
110 while (lo <= hi)
111 {
112 mid = (lo + hi) / 2;
113 if (offset > (off_t)Is[mid].offset)
114 lo = mid+1;
115 else if (offset < (off_t)Is[mid].offset)
116 hi = mid-1;
117 else
118 return (Instr *)&Is[mid];
119 }
120 if ((off_t)Is[mid].offset < offset)
121 mid++;
122 return (Is[mid].offset == 0? nullptr: (Instr *)&Is[mid]);
123}
124
125/*
126 * Find the instruction for the given offset.

Callers 5

emitRefactoredPatchFunction · 0.80
main_2Function · 0.80
findLineMethod · 0.80
lookupSymbolFunction · 0.80
lookupSymbolWarningsFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected