| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | // =========================================================================== |
| 5 | // File: CeeSectionString.h |
| 6 | // |
| 7 | // =========================================================================== |
| 8 | |
| 9 | #ifndef CeeSectionString_H |
| 10 | #define CeeSectionString_H |
| 11 | |
| 12 | #include <ole2.h> |
| 13 | #include "ceegen.h" |
| 14 | |
| 15 | // This class is responsible for managing all the strings that have |
| 16 | // been emitted for the PE file. |
| 17 | |
| 18 | // This class manages the strings that are added to the .rdata section. |
| 19 | // It keeps track of each string that has been added using a hashtable. |
| 20 | // The hash table is effectively 2-dimensional. There is a large "virtual |
| 21 | // hash space" that is used to get a wide hash code distribution. The |
| 22 | // virtual hash space is mapped into a real hash table where each n |
| 23 | // hash values in the virtual space fall into a given hash bucket for |
| 24 | // real hash table size n. Within the bucket, elements are stored in a linked |
| 25 | // list in-order. When an virtual hash entry corresponds to a given bucket, |
| 26 | // that bucket is searched for the matching hash id. If not found, it is |
| 27 | // inserted, otherwise, the value is returned. The idea is that for smaller |
| 28 | // apps, there won't be a large number of strings, so that collisions are |
| 29 | // minimal and the length of each bucket's chain is small. For larger |
| 30 | // numbers of strings, having a large hash space also reduces numbers |
| 31 | // of collisions, avoiding string compares unless the hash codes match. |
| 32 | |
| 33 | struct StringTableEntry; |
| 34 | |
| 35 | class CeeSectionString : public CeeSection { |
| 36 | enum { MaxRealEntries = 100, MaxVirtualEntries = 10000 }; |
| 37 | StringTableEntry *stringTable[MaxRealEntries]; |
| 38 | |
| 39 | StringTableEntry *createEntry(__in_z LPWSTR target, ULONG hashId); |
| 40 | StringTableEntry *findStringInsert( |
| 41 | StringTableEntry *&entry, __in_z LPWSTR targetValue, ULONG hashId); |
| 42 | void deleteEntries(StringTableEntry *e); |
| 43 | #ifdef RDATA_STATS |
| 44 | int dumpEntries(StringTableEntry *e); |
| 45 | void dumpTable(); |
| 46 | #endif |
| 47 | |
| 48 | public: |
| 49 | ~CeeSectionString(); |
| 50 | CeeSectionString(CCeeGen &ceeFile, CeeSectionImpl &impl); |
| 51 | virtual HRESULT getEmittedStringRef(__in_z LPWSTR targetValue, StringRef *ref); |
| 52 | }; |
| 53 | |
| 54 | #endif |
| 55 | |
| 56 | |