<commit_before>/*
 * Copyright (C) 2008-2010, <NAME>.
 *
 * This software is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the
 * implied warranties of fitness for a particular purpose.
 *
 * See the LICENSE file for more information.
 */

#ifndef LIBPORT_REF_COUNTED_HXX
# define LIBPORT_REF_COUNTED_HXX

# include <libport/cassert>

namespace libport
{
  inline RefCounted::RefCounted ()
    : count_(0)
  {}

  inline RefCounted::~RefCounted ()
  {}

  inline void RefCounted::counter_inc () const
  {
    aver(count_ != 0xFFFFFFFF);
    ++count_;
  }

  // This method is used to avoid extra delete when you are using this
  // object inside the destructor.
  inline void RefCounted::counter_reset () const
  {
    aver(count_ == 0xFFFFFFFF);
    count_ = 1;
  }

  inline bool RefCounted::counter_dec () const
  {
    aver(count_ != 0xFFFFFFFF);
    --count_;
    if (!count_)
    {
      count_ = 0xFFFFFFFF;
      return true;
    }
    return false;
  }

  inline unsigned RefCounted::counter_get () const
  {
    return count_;
  }
}

#endif<commit_msg>RefCounted: factor invalid counter value.<commit_after>/*
 * Copyright (C) 2008-2010, <NAME>.
 *
 * This software is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the
 * implied warranties of fitness for a particular purpose.
 *
 * See the LICENSE file for more information.
 */

#ifndef LIBPORT_REF_COUNTED_HXX
# define LIBPORT_REF_COUNTED_HXX

# include <libport/cassert>

namespace libport
{
  static const unsigned invalid_count = 0xFFFFFFFF;

  inline RefCounted::RefCounted ()
    : count_(0)
  {}

  inline RefCounted::~RefCounted ()
  {}

  inline void RefCounted::counter_inc () const
  {
    aver(count_ != invalid_count);
    ++count_;
  }

  // This method is used to avoid extra delete when you are using this
  // object inside the destructor.
  inline void RefCounted::counter_reset () const
  {
    aver(count_ == invalid_count);
    count_ = 1;
  }

  inline bool RefCounted::counter_dec () const
  {
    aver(count_ != invalid_count);
    --count_;
    if (!count_)
    {
      count_ = invalid_count;
      return true;
    }
    return false;
  }

  inline unsigned RefCounted::counter_get () const
  {
    return count_;
  }
}

#endif
{'fraction_non_alphanumeric': 0.09910294745835113, 'fraction_numerical': 0.010679196924391286, 'mean_word_length': 3.189624329159213, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 5, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3806757', 'n_tokens_mistral': 766, 'n_tokens_neox': 726, 'n_words': 224}