<commit_before>//===-- ClangExternalASTSourceCommon.cpp ------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
#include "lldb/Core/Stream.h"
#include "lldb/Host/Mutex.h"

using namespace lldb_private;

uint64_t g_TotalSizeOfMetadata = 0;

typedef llvm::DenseMap<clang::ExternalASTSource *, ClangExternalASTSourceCommon *> ASTSourceMap;

static ASTSourceMap &GetSourceMap()
{
    static ASTSourceMap s_source_map;
    return s_source_map;
}

ClangExternalASTSourceCommon *
ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source)
{
    ASTSourceMap &source_map = GetSourceMap();
    
    ASTSourceMap::iterator iter = source_map.find(source);
    
    if (iter != source_map.end())
    {
        return iter->second;
    }
    else
    {
        return nullptr;
    }
}

ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() : clang::ExternalASTSource()
{
    g_TotalSizeOfMetadata += m_metadata.size();
    GetSourceMap()[this] = this;
}

ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon()<commit_msg>Intentionally leak the ASTSourceMap instead of destroying it when LLDB quits.<commit_after>//===-- ClangExternalASTSourceCommon.cpp ------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
#include "lldb/Core/Stream.h"
#include "lldb/Host/Mutex.h"

using namespace lldb_private;

uint64_t g_TotalSizeOfMetadata = 0;

typedef llvm::DenseMap<clang::ExternalASTSource *, ClangExternalASTSourceCommon *> ASTSourceMap;

static ASTSourceMap &GetSourceMap()
{
    // Intentionally leaked to avoid problems with global destructors.
    static ASTSourceMap *s_source_map = new ASTSourceMap;
    return *s_source_map;
}

ClangExternalASTSourceCommon *
ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source)
{
    ASTSourceMap &source_map = GetSourceMap();
    
    ASTSourceMap::iterator iter = source_map.find(source);
    
    if (iter != source_map.end())
    {
        return iter->second;
    }
    else
    {
        return nullptr;
    }
}

ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() : clang::ExternalASTSource()
{
    g_TotalSizeOfMetadata += m_metadata.size();
    GetSourceMap()[this] = this;
}

ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon()
{'fraction_non_alphanumeric': 0.17611622962437987, 'fraction_numerical': 0.002126151665485471, 'mean_word_length': 3.0042553191489363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7241051', 'n_tokens_mistral': 832, 'n_tokens_neox': 812, 'n_words': 161}