filename-seen-cache.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Filename-seen cache for the GNU debugger, GDB.
  2. Copyright (C) 1986-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "filename-seen-cache.h"
  16. #include "filenames.h"
  17. /* Initial size of the table. It automagically grows from here. */
  18. #define INITIAL_FILENAME_SEEN_CACHE_SIZE 100
  19. /* filename_seen_cache constructor. */
  20. filename_seen_cache::filename_seen_cache ()
  21. : m_tab (htab_create_alloc (INITIAL_FILENAME_SEEN_CACHE_SIZE,
  22. filename_hash, filename_eq,
  23. NULL, xcalloc, xfree))
  24. {
  25. }
  26. /* See filename-seen-cache.h. */
  27. void
  28. filename_seen_cache::clear ()
  29. {
  30. htab_empty (m_tab.get ());
  31. }
  32. /* See filename-seen-cache.h. */
  33. bool
  34. filename_seen_cache::seen (const char *file)
  35. {
  36. void **slot;
  37. /* Is FILE in tab? */
  38. slot = htab_find_slot (m_tab.get (), file, INSERT);
  39. if (*slot != NULL)
  40. return true;
  41. /* No; add it to tab. */
  42. *slot = (char *) file;
  43. return false;
  44. }