Files
textmate/Frameworks/OakDebug/src/OakWatchLeaks.cc
Allan Odgaard c2397484b8 Use C++11 for loop
Majority of the edits done using the following ruby script:

    def update_loops(src)
      dst, cnt = '', 0

      block_indent, variable = nil, nil
      src.each_line do |line|
        if block_indent
          if line =~ /^#{block_indent}([{}\t])|^\t*$/
            block_indent = nil if $1 == '}'
            line = line.gsub(%r{ ([^a-z>]) \(\*#{variable}\) | \*#{variable}\b | \b#{variable}(->) }x) do
              $1.to_s + variable + ($2 == "->" ? "." : "")
            end
          else
            block_indent = nil
          end
        elsif line =~ /^(\t*)c?iterate\((\w+), (?!diacritics::make_range)(.*\))$/
          block_indent, variable = $1, $2
          line = "#$1for(auto const& #$2 : #$3\n"
          cnt += 1
        end
        dst << line
      end
      return dst, cnt
    end

    paths.each do |path|
      src = IO.read(path)

      cnt = 1
      while cnt != 0
        src, cnt = update_loops(src)
        STDERR << "#{path}: #{cnt}\n"
      end

      File.open(path, "w") { |io| io << src }
    end
2014-03-03 10:34:13 +07:00

55 lines
996 B
C++

#include "OakDebug.h"
#include <oak/oak.h>
namespace
{
static OSSpinLock spinlock = 0;
struct counts_t
{
counts_t (std::map<std::string, ssize_t>& counts) : counts(counts) { }
~counts_t () { OSSpinLockUnlock(&spinlock); }
std::map<std::string, ssize_t>& counts;
};
static counts_t get_counts ()
{
OSSpinLockLock(&spinlock);
static std::map<std::string, ssize_t>* counts = NULL;
if(counts == NULL)
counts = new std::map<std::string, ssize_t>;
return counts_t(*counts);
}
static struct helper_t
{
~helper_t ()
{
for(auto const& it : get_counts().counts)
{
if(it.second != 0)
bug("%4zd: %s\n", it.second, it.first.c_str());
}
}
} helper;
}
namespace oak_debug
{
void increase (char const* name)
{
counts_t c = get_counts();
++c.counts[name];
}
void decrease (char const* name)
{
counts_t c = get_counts();
ASSERTF(c.counts[name] > 0, "name = %s, count = %zd\n", name, c.counts[name]);
--c.counts[name];
}
} /* oak_debug */