xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/filename-seen-cache.c (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
17f2ac410Schristos /* Filename-seen cache for the GNU debugger, GDB.
27f2ac410Schristos 
3*6881a400Schristos    Copyright (C) 1986-2023 Free Software Foundation, Inc.
47f2ac410Schristos 
57f2ac410Schristos    This file is part of GDB.
67f2ac410Schristos 
77f2ac410Schristos    This program is free software; you can redistribute it and/or modify
87f2ac410Schristos    it under the terms of the GNU General Public License as published by
97f2ac410Schristos    the Free Software Foundation; either version 3 of the License, or
107f2ac410Schristos    (at your option) any later version.
117f2ac410Schristos 
127f2ac410Schristos    This program is distributed in the hope that it will be useful,
137f2ac410Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
147f2ac410Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
157f2ac410Schristos    GNU General Public License for more details.
167f2ac410Schristos 
177f2ac410Schristos    You should have received a copy of the GNU General Public License
187f2ac410Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
197f2ac410Schristos 
207f2ac410Schristos #include "defs.h"
217f2ac410Schristos #include "filename-seen-cache.h"
227f2ac410Schristos #include "filenames.h"
237f2ac410Schristos 
247f2ac410Schristos   /* Initial size of the table.  It automagically grows from here.  */
257f2ac410Schristos #define INITIAL_FILENAME_SEEN_CACHE_SIZE 100
267f2ac410Schristos 
277f2ac410Schristos /* filename_seen_cache constructor.  */
287f2ac410Schristos 
297f2ac410Schristos filename_seen_cache::filename_seen_cache ()
30*6881a400Schristos   : m_tab (htab_create_alloc (INITIAL_FILENAME_SEEN_CACHE_SIZE,
317f2ac410Schristos 			      filename_hash, filename_eq,
32*6881a400Schristos 			      NULL, xcalloc, xfree))
33*6881a400Schristos {
347f2ac410Schristos }
357f2ac410Schristos 
367f2ac410Schristos /* See filename-seen-cache.h.  */
377f2ac410Schristos 
387f2ac410Schristos void
397f2ac410Schristos filename_seen_cache::clear ()
407f2ac410Schristos {
41*6881a400Schristos   htab_empty (m_tab.get ());
427f2ac410Schristos }
437f2ac410Schristos 
447f2ac410Schristos /* See filename-seen-cache.h.  */
457f2ac410Schristos 
467f2ac410Schristos bool
477f2ac410Schristos filename_seen_cache::seen (const char *file)
487f2ac410Schristos {
497f2ac410Schristos   void **slot;
507f2ac410Schristos 
517f2ac410Schristos   /* Is FILE in tab?  */
52*6881a400Schristos   slot = htab_find_slot (m_tab.get (), file, INSERT);
537f2ac410Schristos   if (*slot != NULL)
547f2ac410Schristos     return true;
557f2ac410Schristos 
567f2ac410Schristos   /* No; add it to tab.  */
577f2ac410Schristos   *slot = (char *) file;
587f2ac410Schristos   return false;
597f2ac410Schristos }
60