def _ApplySizeLimit(regions,
                    size_limit):
  """Truncates regions so that the total size stays in size_limit."""
  total_size = 0
  regions_in_limit = []
  for region in regions:
    total_size += region.size
    if total_size > size_limit:
      break
    regions_in_limit.append(region)
  return regions_in_limit