MCPcopy Create free account
hub / github.com/WinMerge/winmerge / CreateVirtualLineToRealLineMap

Function CreateVirtualLineToRealLineMap

Src/MergeDocDiffSync.cpp:91–119  ·  view source on GitHub ↗

* @brief Create map from virtual line to real line. */

Source from the content-addressed store, hash-verified

89 * @brief Create map from virtual line to real line.
90 */
91static std::vector<std::array<int, 2>>
92CreateVirtualLineToRealLineMap(
93 const DiffMap& diffmap, int nlines0, int nlines1)
94{
95 std::vector<std::array<int, 2>> vlines;
96 vlines.reserve((std::max)(nlines0, nlines1) * 3 / 2); // Roughly pre-allocate space for the list.
97 int line0 = 0, line1 = 0;
98 while (line0 < nlines0)
99 {
100 const int map_line0 = diffmap.m_map[line0];
101 if (map_line0 == DiffMap::GHOST_MAP_ENTRY || map_line0 == DiffMap::BAD_MAP_ENTRY)
102 {
103 vlines.push_back({ line0++, DiffMap::GHOST_MAP_ENTRY });
104 }
105 else
106 {
107 while (line1 < map_line0)
108 vlines.push_back({ DiffMap::GHOST_MAP_ENTRY, line1++ });
109 vlines.push_back({ line0++, line1++ });
110 }
111 }
112 while (line1 < nlines1)
113 vlines.push_back({ DiffMap::GHOST_MAP_ENTRY, line1++ });
114 ValidateVirtualLineToRealLineMap(vlines, std::array<int, 2>{ nlines0, nlines1 });
115#ifdef _DEBUG
116 PrintVirtualLineToRealLineMap(_T("vline"), vlines);
117#endif
118 return vlines;
119}
120
121/**
122 * @brief Create map from virtual line to real line. (3-way)

Callers 2

AdjustDiffBlocksMethod · 0.85

Calls 3

reserveMethod · 0.45

Tested by

no test coverage detected