1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/jprof/strset.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,40 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "strset.h" 1.9 +#include <malloc.h> 1.10 +#include <string.h> 1.11 + 1.12 +StrSet::StrSet() 1.13 +{ 1.14 + strings = 0; 1.15 + numstrings = 0; 1.16 +} 1.17 + 1.18 +void StrSet::add(const char* s) 1.19 +{ 1.20 + if (strings) { 1.21 + strings = (char**) realloc(strings, (numstrings + 1) * sizeof(char*)); 1.22 + } else { 1.23 + strings = (char**) malloc(sizeof(char*)); 1.24 + } 1.25 + strings[numstrings] = strdup(s); 1.26 + numstrings++; 1.27 +} 1.28 + 1.29 +int StrSet::contains(const char* s) 1.30 +{ 1.31 + char** sp = strings; 1.32 + int i = numstrings; 1.33 + 1.34 + while (--i >= 0) { 1.35 + char *ss = *sp++; 1.36 + if (ss[0] == s[0]) { 1.37 + if (strcmp(ss, s) == 0) { 1.38 + return 1; 1.39 + } 1.40 + } 1.41 + } 1.42 + return 0; 1.43 +}