コード例 #1
0
 internal void AddSegment(int offset)
 {
     // If this page isn't null and the offset isn't already recorded...
     if (BlockSizeUncompressed.Value != 0 && !SegmentOffsets.Contains(offset))
     {
         SegmentOffsets.Add(offset);
         SegmentSizes.Add(-1);                     // we'll update this when we post-process in 'CalculateSegmentSizes'
     }
 }
コード例 #2
0
            internal void CalculateSegmentSizes()
            {
                // If this page isn't null
                if (BlockSizeUncompressed.Value == 0)
                {
                    return;
                }

                // We work backwards to find the sizes as we can just find the
                // distances between each segment. For the last segment we can
                // just use the page size minus the offset to find it's size
                int last_element = SegmentOffsets.Count - 1;

                // TODO: there should be at least one segment referencing this page...?
                if (last_element == -1)
                {
                    SegmentOffsets.Add(0);
                    SegmentSizes.Add(BlockSizeUncompressed.Value);
                }
                // we only have one element so no point in loopin'
                else if (last_element == 0)
                {
                    SegmentSizes[0] = BlockSizeUncompressed.Value;
                }
                else
                {
                    // figure out the segment sizes via the next
                    // segment's offset after 'x' segment
                    SegmentOffsets.Sort();                     // loop depends on the offsets being linear

                    // Figure out the last segment first. This used to be done
                    // in the for loop with a check 'x == last_element' but doing
                    // it here leaves out that boolean check and possible code
                    // jump in the result code
                    SegmentSizes[last_element] = BlockSizeUncompressed.Value - SegmentOffsets[last_element];
                    for (int x = last_element - 1; x >= 0; x--)
                    {
                        SegmentSizes[x] = SegmentOffsets[x + 1] - SegmentOffsets[x];
                    }
                }
            }