comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java @ 16989:19faa7ca37c1

Truffle/Source: use a synchronized hash table
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Wed, 27 Aug 2014 17:59:48 -0700
parents 7109baa7b9eb
children 0bcefb0f8488
comparison
equal deleted inserted replaced
16988:225ce2657c55 16989:19faa7ca37c1
71 71
72 // TODO (mlvdv) consider canonicalizing and reusing SourceSection instances 72 // TODO (mlvdv) consider canonicalizing and reusing SourceSection instances
73 // TOOD (mlvdv) connect SourceSections into a spatial tree for fast geometric lookup 73 // TOOD (mlvdv) connect SourceSections into a spatial tree for fast geometric lookup
74 74
75 // Files and pseudo files are indexed. 75 // Files and pseudo files are indexed.
76 private static final Map<String, WeakReference<Source>> filePathToSource = new HashMap<>(); 76 private static final Map<String, WeakReference<Source>> filePathToSource = new Hashtable<>();
77 77
78 private static boolean fileCacheEnabled = true; 78 private static boolean fileCacheEnabled = true;
79 79
80 /** 80 /**
81 * Gets the canonical representation of a source file, whose contents will be read lazily and 81 * Gets the canonical representation of a source file, whose contents will be read lazily and
169 final Source source = new LiteralSource(pseudoFileName, code); 169 final Source source = new LiteralSource(pseudoFileName, code);
170 filePathToSource.put(pseudoFileName, new WeakReference<>(source)); 170 filePathToSource.put(pseudoFileName, new WeakReference<>(source));
171 return source; 171 return source;
172 } 172 }
173 173
174 // TODO (mlvdv) enable per-file choice whether to cache?
174 /** 175 /**
175 * Enables/disables caching of file contents, <em>disabled</em> by default. Caching of sources 176 * Enables/disables caching of file contents, <em>disabled</em> by default. Caching of sources
176 * created from literal text or readers is always enabled. 177 * created from literal text or readers is always enabled.
177 */ 178 */
178 public static void setFileCaching(boolean enabled) { 179 public static void setFileCaching(boolean enabled) {