11cb0ef41Sopenharmony_ci// Copyright 2010 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/utils/bit-vector.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "src/base/bits.h"
81cb0ef41Sopenharmony_ci#include "src/utils/utils.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cinamespace v8 {
111cb0ef41Sopenharmony_cinamespace internal {
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci#ifdef DEBUG
141cb0ef41Sopenharmony_civoid BitVector::Print() const {
151cb0ef41Sopenharmony_ci  bool first = true;
161cb0ef41Sopenharmony_ci  PrintF("{");
171cb0ef41Sopenharmony_ci  for (int i = 0; i < length(); i++) {
181cb0ef41Sopenharmony_ci    if (Contains(i)) {
191cb0ef41Sopenharmony_ci      if (!first) PrintF(",");
201cb0ef41Sopenharmony_ci      first = false;
211cb0ef41Sopenharmony_ci      PrintF("%d", i);
221cb0ef41Sopenharmony_ci    }
231cb0ef41Sopenharmony_ci  }
241cb0ef41Sopenharmony_ci  PrintF("}\n");
251cb0ef41Sopenharmony_ci}
261cb0ef41Sopenharmony_ci#endif
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciint BitVector::Count() const {
291cb0ef41Sopenharmony_ci  if (is_inline()) return base::bits::CountPopulation(data_.inline_);
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  int count = 0;
321cb0ef41Sopenharmony_ci  for (int i = 0; i < data_length_; i++) {
331cb0ef41Sopenharmony_ci    count += base::bits::CountPopulation(data_.ptr_[i]);
341cb0ef41Sopenharmony_ci  }
351cb0ef41Sopenharmony_ci  return count;
361cb0ef41Sopenharmony_ci}
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci}  // namespace internal
391cb0ef41Sopenharmony_ci}  // namespace v8
40