@@ -35,6 +35,105 @@ void SourceMap::swapWith(ThisType& rhs)
35
35
m_slicePool.swapWith (rhs.m_slicePool );
36
36
}
37
37
38
+ static bool _areEqual (const List<StringSlicePool::Handle >& a, const List<StringSlicePool::Handle >& b, const List<Index>& bToAMap)
39
+ {
40
+ const auto count = a.getCount ();
41
+ if (count != b.getCount ())
42
+ {
43
+ return false ;
44
+ }
45
+
46
+ const auto * as = a.getBuffer ();
47
+ const auto * bs = a.getBuffer ();
48
+
49
+ for (Index i = 0 ; i < count; ++i)
50
+ {
51
+ if (StringSlicePool::asIndex (as[i]) != bToAMap[StringSlicePool::asIndex (bs[i])])
52
+ {
53
+ return false ;
54
+ }
55
+ }
56
+
57
+ return true ;
58
+ }
59
+
60
+ static bool _areEqual (const SourceMap::Entry& a, const SourceMap::Entry& b, const List<Index>& bToAMap)
61
+ {
62
+ return a.generatedColumn == b.generatedColumn &&
63
+ a.sourceLine == b.sourceLine &&
64
+ a.sourceColumn == b.sourceColumn &&
65
+ a.sourceFileIndex == bToAMap[b.sourceFileIndex ] &&
66
+ a.nameIndex == bToAMap[b.nameIndex ];
67
+ }
68
+
69
+ static bool _areEqual (const List<SourceMap::Entry>& a, const List<SourceMap::Entry>&b, const List<Index>& bToAMap)
70
+ {
71
+ const auto count = a.getCount ();
72
+ if (count != b.getCount ())
73
+ {
74
+ return false ;
75
+ }
76
+
77
+ for (Index i = 0 ; i < count; ++i)
78
+ {
79
+ if (!_areEqual (a[i], b[i], bToAMap))
80
+ {
81
+ return false ;
82
+ }
83
+ }
84
+
85
+ return true ;
86
+ }
87
+
88
+ bool SourceMap::operator ==(const ThisType& rhs) const
89
+ {
90
+ if (this == &rhs)
91
+ {
92
+ return true ;
93
+ }
94
+
95
+ if (m_file != rhs.m_file ||
96
+ m_sourceRoot != rhs.m_sourceRoot ||
97
+ m_lineStarts != rhs.m_lineStarts )
98
+ {
99
+ return false ;
100
+ }
101
+
102
+ if (m_slicePool == rhs.m_slicePool )
103
+ {
104
+ // If the slice pools are the same we can just compare indices directly
105
+ return m_sources == rhs.m_sources &&
106
+ m_sourcesContent == rhs.m_sourcesContent &&
107
+ m_names == rhs.m_names &&
108
+ m_lineEntries == rhs.m_lineEntries ;
109
+ }
110
+ else
111
+ {
112
+ // Otherwise we need to remap the indices
113
+ // Maps a pool handle from the rhs source map to the
114
+ List<Index> rhsMap;
115
+
116
+ Count count = rhs.m_slicePool .getSlicesCount ();
117
+
118
+ rhsMap.setCount (count);
119
+
120
+ const auto startIndex = rhs.m_slicePool .getFirstAddedIndex ();
121
+
122
+ // Work out the map
123
+ for (Index i = 0 ; i < startIndex; ++i)
124
+ {
125
+ const auto rhsSlice = rhs.m_slicePool .getSlice (StringSlicePool::Handle (i));
126
+ rhsMap[i] = (i < startIndex) ? i : m_slicePool.findIndex (rhsSlice);
127
+ }
128
+
129
+ // Do the comparison taking into account the mapping.
130
+ return _areEqual (m_sources, rhs.m_sources , rhsMap) &&
131
+ _areEqual (m_sourcesContent, rhs.m_sourcesContent , rhsMap) &&
132
+ _areEqual (m_names, rhs.m_names , rhsMap) &&
133
+ _areEqual (m_lineEntries, rhs.m_lineEntries , rhsMap);
134
+ }
135
+ }
136
+
38
137
void SourceMap::advanceToLine (Index nextLineIndex)
39
138
{
40
139
const Count currentLineIndex = getGeneratedLineCount () - 1 ;
0 commit comments