File: cstrcache.cpp

package info (click to toggle)
obs-studio 22.0.3%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 23,052 kB
  • sloc: ansic: 134,708; cpp: 49,169; objc: 1,036; makefile: 829; sh: 410; python: 360
file content (28 lines) | stat: -rw-r--r-- 463 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <unordered_map>
#include <string>

#include "cstrcache.h"

using namespace std;

struct const_string_table {
	unordered_map<string, string> strings;
};

static struct const_string_table table;

const char *cstrcache_get(const char *str)
{
	if (!str || !*str)
		return "";

	auto &strings = table.strings;
	auto pair = strings.find(str);

	if (pair == strings.end()) {
		strings[str] = str;
		pair = strings.find(str);
	}

	return pair->second.c_str();
}