Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/tools/profiler/lul/LulCommon.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
4
// Copyright (c) 2011, 2013 Google Inc.
5
// All rights reserved.
6
//
7
// Redistribution and use in source and binary forms, with or without
8
// modification, are permitted provided that the following conditions are
9
// met:
10
//
11
//     * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
//     * Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
16
// distribution.
17
//     * Neither the name of Google Inc. nor the names of its
18
// contributors may be used to endorse or promote products derived from
19
// this software without specific prior written permission.
20
//
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33
// Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
34
35
36
// This file is derived from the following files in
37
// toolkit/crashreporter/google-breakpad:
38
//   src/common/module.cc
39
//   src/common/unique_string.cc
40
41
// There's no internal-only interface for LulCommon.  Hence include
42
// the external interface directly.
43
#include "LulCommonExt.h"
44
45
#include <stdlib.h>
46
#include <string.h>
47
48
#include <string>
49
#include <map>
50
51
52
namespace lul {
53
54
using std::string;
55
56
////////////////////////////////////////////////////////////////
57
// Module
58
//
59
Module::Module(const string &name, const string &os,
60
               const string &architecture, const string &id) :
61
    name_(name),
62
    os_(os),
63
    architecture_(architecture),
64
0
    id_(id) { }
65
66
0
Module::~Module() {
67
0
}
68
69
70
////////////////////////////////////////////////////////////////
71
// UniqueString
72
//
73
class UniqueString {
74
 public:
75
0
  explicit UniqueString(string str) { str_ = strdup(str.c_str()); }
76
0
  ~UniqueString() { free(reinterpret_cast<void*>(const_cast<char*>(str_))); }
77
  const char* str_;
78
};
79
80
const char* FromUniqueString(const UniqueString* ustr)
81
0
{
82
0
  return ustr->str_;
83
0
}
84
85
bool IsEmptyUniqueString(const UniqueString* ustr)
86
0
{
87
0
  return (ustr->str_)[0] == '\0';
88
0
}
89
90
91
////////////////////////////////////////////////////////////////
92
// UniqueStringUniverse
93
//
94
UniqueStringUniverse::~UniqueStringUniverse()
95
0
{
96
0
  for (std::map<string, UniqueString*>::iterator it = map_.begin();
97
0
       it != map_.end(); it++) {
98
0
    delete it->second;
99
0
  }
100
0
}
101
102
const UniqueString* UniqueStringUniverse::ToUniqueString(string str)
103
0
{
104
0
  std::map<string, UniqueString*>::iterator it = map_.find(str);
105
0
  if (it == map_.end()) {
106
0
    UniqueString* ustr = new UniqueString(str);
107
0
    map_[str] = ustr;
108
0
    return ustr;
109
0
  } else {
110
0
    return it->second;
111
0
  }
112
0
}
113
114
}  // namespace lul