Bug 1874683 - Part 10: Inline String.prototype.at in CacheIR. r=jandem
[gecko.git] / tools / jprof / strset.cpp
blob514b8c03e0fda90f3234b6fa581eca527b539a53
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "strset.h"
6 #include <malloc.h>
7 #include <string.h>
9 StrSet::StrSet() {
10 strings = 0;
11 numstrings = 0;
14 void StrSet::add(const char* s) {
15 if (strings) {
16 strings = (char**)realloc(strings, (numstrings + 1) * sizeof(char*));
17 } else {
18 strings = (char**)malloc(sizeof(char*));
20 strings[numstrings] = strdup(s);
21 numstrings++;
24 int StrSet::contains(const char* s) {
25 char** sp = strings;
26 int i = numstrings;
28 while (--i >= 0) {
29 char* ss = *sp++;
30 if (ss[0] == s[0]) {
31 if (strcmp(ss, s) == 0) {
32 return 1;
36 return 0;