156698Sjasone/* Filename-seen cache for the GNU debugger, GDB.
263364Sjasone
356698Sjasone   Copyright (C) 1986-2020 Free Software Foundation, Inc.
456698Sjasone
556698Sjasone   This file is part of GDB.
656698Sjasone
756698Sjasone   This program is free software; you can redistribute it and/or modify
856698Sjasone   it under the terms of the GNU General Public License as published by
956698Sjasone   the Free Software Foundation; either version 3 of the License, or
1056698Sjasone   (at your option) any later version.
1156698Sjasone
1256698Sjasone   This program is distributed in the hope that it will be useful,
1356698Sjasone   but WITHOUT ANY WARRANTY; without even the implied warranty of
1456698Sjasone   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1556698Sjasone   GNU General Public License for more details.
1656698Sjasone
1756698Sjasone   You should have received a copy of the GNU General Public License
1856698Sjasone   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1956698Sjasone
2056698Sjasone#include "defs.h"
2156698Sjasone#include "filename-seen-cache.h"
2256698Sjasone#include "filenames.h"
2356698Sjasone
2456698Sjasone  /* Initial size of the table.  It automagically grows from here.  */
2556698Sjasone#define INITIAL_FILENAME_SEEN_CACHE_SIZE 100
2656698Sjasone
2756698Sjasone/* filename_seen_cache constructor.  */
2856698Sjasone
2956698Sjasonefilename_seen_cache::filename_seen_cache ()
3056698Sjasone{
3156698Sjasone  m_tab = htab_create_alloc (INITIAL_FILENAME_SEEN_CACHE_SIZE,
32174112Sdeischen			     filename_hash, filename_eq,
3356698Sjasone			     NULL, xcalloc, xfree);
3456698Sjasone}
35174112Sdeischen
36103388Smini/* See filename-seen-cache.h.  */
3756698Sjasone
38174112Sdeischenvoid
39119723Sdeischenfilename_seen_cache::clear ()
40119723Sdeischen{
4175369Sdeischen  htab_empty (m_tab);
4271581Sdeischen}
4356698Sjasone
4471581Sdeischen/* See filename-seen-cache.h.  */
4556698Sjasone
46113658Sdeischenfilename_seen_cache::~filename_seen_cache ()
4756698Sjasone{
4856698Sjasone  htab_delete (m_tab);
49123312Sdavidxu}
5056698Sjasone
51123312Sdavidxu/* See filename-seen-cache.h.  */
5256698Sjasone
53113658Sdeischenbool
5456698Sjasonefilename_seen_cache::seen (const char *file)
55{
56  void **slot;
57
58  /* Is FILE in tab?  */
59  slot = htab_find_slot (m_tab, file, INSERT);
60  if (*slot != NULL)
61    return true;
62
63  /* No; add it to tab.  */
64  *slot = (char *) file;
65  return false;
66}
67