@@ -1875,17 +1875,20 @@ test diff {
18751875}
18761876
18771877test diffCleanupSemantic {
1878+ var arena = std .heap .ArenaAllocator .init (talloc );
1879+ defer arena .deinit ();
1880+
18781881 // Cleanup semantically trivial equalities.
18791882 // Null case.
18801883 var diffs = std .ArrayListUnmanaged (Diff ){};
1881- defer diffs .deinit (talloc );
1884+ defer diffs .deinit (arena . allocator () );
18821885 // var this = default;
1883- try diffCleanupSemantic (talloc , & diffs );
1886+ try diffCleanupSemantic (arena . allocator () , & diffs );
18841887 try std .testing .expectEqual (@as (usize , 0 ), diffs .items .len ); // Null case
18851888
18861889 diffs .items .len = 0 ;
1887- try diffs .appendSlice (talloc , &.{ Diff .init (.delete , "ab" ), Diff .init (.insert , "cd" ), Diff .init (.equal , "12" ), Diff .init (.delete , "e" ) });
1888- try diffCleanupSemantic (talloc , & diffs );
1890+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.delete , "ab" ), Diff .init (.insert , "cd" ), Diff .init (.equal , "12" ), Diff .init (.delete , "e" ) });
1891+ try diffCleanupSemantic (arena . allocator () , & diffs );
18891892 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // No elimination #1
18901893 Diff .init (.delete , "ab" ),
18911894 Diff .init (.insert , "cd" ),
@@ -1894,8 +1897,8 @@ test diffCleanupSemantic {
18941897 }), diffs .items );
18951898
18961899 diffs .items .len = 0 ;
1897- try diffs .appendSlice (talloc , &.{ Diff .init (.delete , "abc" ), Diff .init (.insert , "ABC" ), Diff .init (.equal , "1234" ), Diff .init (.delete , "wxyz" ) });
1898- try diffCleanupSemantic (talloc , & diffs );
1900+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.delete , "abc" ), Diff .init (.insert , "ABC" ), Diff .init (.equal , "1234" ), Diff .init (.delete , "wxyz" ) });
1901+ try diffCleanupSemantic (arena . allocator () , & diffs );
18991902 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // No elimination #2
19001903 Diff .init (.delete , "abc" ),
19011904 Diff .init (.insert , "ABC" ),
@@ -1904,67 +1907,67 @@ test diffCleanupSemantic {
19041907 }), diffs .items );
19051908
19061909 diffs .items .len = 0 ;
1907- try diffs .appendSlice (talloc , &.{ Diff .init (.delete , "a" ), Diff .init (.equal , "b" ), Diff .init (.delete , "c" ) });
1908- try diffCleanupSemantic (talloc , & diffs );
1910+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.delete , "a" ), Diff .init (.equal , "b" ), Diff .init (.delete , "c" ) });
1911+ try diffCleanupSemantic (arena . allocator () , & diffs );
19091912 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // Simple elimination
19101913 Diff .init (.delete , "abc" ),
19111914 Diff .init (.insert , "b" ),
19121915 }), diffs .items );
19131916
19141917 diffs .items .len = 0 ;
1915- try diffs .appendSlice (talloc , &.{ Diff .init (.delete , "ab" ), Diff .init (.equal , "cd" ), Diff .init (.delete , "e" ), Diff .init (.equal , "f" ), Diff .init (.insert , "g" ) });
1916- try diffCleanupSemantic (talloc , & diffs );
1918+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.delete , "ab" ), Diff .init (.equal , "cd" ), Diff .init (.delete , "e" ), Diff .init (.equal , "f" ), Diff .init (.insert , "g" ) });
1919+ try diffCleanupSemantic (arena . allocator () , & diffs );
19171920 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // Backpass elimination
19181921 Diff .init (.delete , "abcdef" ),
19191922 Diff .init (.insert , "cdfg" ),
19201923 }), diffs .items );
19211924
19221925 diffs .items .len = 0 ;
1923- try diffs .appendSlice (talloc , &.{ Diff .init (.insert , "1" ), Diff .init (.equal , "A" ), Diff .init (.delete , "B" ), Diff .init (.insert , "2" ), Diff .init (.equal , "_" ), Diff .init (.insert , "1" ), Diff .init (.equal , "A" ), Diff .init (.delete , "B" ), Diff .init (.insert , "2" ) });
1924- try diffCleanupSemantic (talloc , & diffs );
1926+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.insert , "1" ), Diff .init (.equal , "A" ), Diff .init (.delete , "B" ), Diff .init (.insert , "2" ), Diff .init (.equal , "_" ), Diff .init (.insert , "1" ), Diff .init (.equal , "A" ), Diff .init (.delete , "B" ), Diff .init (.insert , "2" ) });
1927+ try diffCleanupSemantic (arena . allocator () , & diffs );
19251928 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // Multiple elimination
19261929 Diff .init (.delete , "AB_AB" ),
19271930 Diff .init (.insert , "1A2_1A2" ),
19281931 }), diffs .items );
19291932
19301933 diffs .items .len = 0 ;
1931- try diffs .appendSlice (talloc , &.{ Diff .init (.equal , "The c" ), Diff .init (.delete , "ow and the c" ), Diff .init (.equal , "at." ) });
1932- try diffCleanupSemantic (talloc , & diffs );
1934+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.equal , "The c" ), Diff .init (.delete , "ow and the c" ), Diff .init (.equal , "at." ) });
1935+ try diffCleanupSemantic (arena . allocator () , & diffs );
19331936 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // Word boundaries
19341937 Diff .init (.equal , "The " ),
19351938 Diff .init (.delete , "cow and the " ),
19361939 Diff .init (.equal , "cat." ),
19371940 }), diffs .items );
19381941
19391942 diffs .items .len = 0 ;
1940- try diffs .appendSlice (talloc , &.{ Diff .init (.delete , "abcxx" ), Diff .init (.insert , "xxdef" ) });
1941- try diffCleanupSemantic (talloc , & diffs );
1943+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.delete , "abcxx" ), Diff .init (.insert , "xxdef" ) });
1944+ try diffCleanupSemantic (arena . allocator () , & diffs );
19421945 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // No overlap elimination
19431946 Diff .init (.delete , "abcxx" ),
19441947 Diff .init (.insert , "xxdef" ),
19451948 }), diffs .items );
19461949
19471950 diffs .items .len = 0 ;
1948- try diffs .appendSlice (talloc , &.{ Diff .init (.delete , "abcxxx" ), Diff .init (.insert , "xxxdef" ) });
1949- try diffCleanupSemantic (talloc , & diffs );
1951+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.delete , "abcxxx" ), Diff .init (.insert , "xxxdef" ) });
1952+ try diffCleanupSemantic (arena . allocator () , & diffs );
19501953 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // Overlap elimination
19511954 Diff .init (.delete , "abc" ),
19521955 Diff .init (.equal , "xxx" ),
19531956 Diff .init (.insert , "def" ),
19541957 }), diffs .items );
19551958
19561959 diffs .items .len = 0 ;
1957- try diffs .appendSlice (talloc , &.{ Diff .init (.delete , "xxxabc" ), Diff .init (.insert , "defxxx" ) });
1958- try diffCleanupSemantic (talloc , & diffs );
1960+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.delete , "xxxabc" ), Diff .init (.insert , "defxxx" ) });
1961+ try diffCleanupSemantic (arena . allocator () , & diffs );
19591962 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // Reverse overlap elimination
19601963 Diff .init (.insert , "def" ),
19611964 Diff .init (.equal , "xxx" ),
19621965 Diff .init (.delete , "abc" ),
19631966 }), diffs .items );
19641967
19651968 diffs .items .len = 0 ;
1966- try diffs .appendSlice (talloc , &.{ Diff .init (.delete , "abcd1212" ), Diff .init (.insert , "1212efghi" ), Diff .init (.equal , "----" ), Diff .init (.delete , "A3" ), Diff .init (.insert , "3BC" ) });
1967- try diffCleanupSemantic (talloc , & diffs );
1969+ try diffs .appendSlice (arena . allocator () , &.{ Diff .init (.delete , "abcd1212" ), Diff .init (.insert , "1212efghi" ), Diff .init (.equal , "----" ), Diff .init (.delete , "A3" ), Diff .init (.insert , "3BC" ) });
1970+ try diffCleanupSemantic (arena . allocator () , & diffs );
19681971 try std .testing .expectEqualDeep (@as ([]const Diff , &[_ ]Diff { // Two overlap eliminations
19691972 Diff .init (.delete , "abcd" ),
19701973 Diff .init (.equal , "1212" ),
0 commit comments