This shows you the differences between two versions of the page.
Last revision | |||
— | dev:hstring [2016/02/25 13:33] – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== HString ====== | ||
+ | **deep** was developed with efficiency and speed in mind. String handling in Java is not very efficient. However, strings are widely used in a compiler. Therefore, we don't use regular Java strings ('' | ||
+ | * A HString must be registered before it can be used. A table contains all the registered HStrings. | ||
+ | * A registered HString exists exactly once. If two HStrings like "Hello World" are created and registered both references point to the same HString-object! | ||
+ | * Two registered HStrings can be compared by comparing there references. | ||
+ | * Be careful: two HStrings can only be compared if they were registered before. | ||
+ | * The central HString-table is created once. If a project is recompiled already registered HStrings remain in the table. | ||
+ | |||
+ | ===== Implementation ===== | ||
+ | [{{ .: | ||
+ | Most strings contain characters which fit into 8 bit. If not 16 bits have to be used. This consumes more memory. | ||
+ | ===== Correct Use ===== | ||
+ | HStrings must be registered before they can be used. This is done with | ||
+ | <code java> | ||
+ | HString.getRegisteredHString(" | ||
+ | </ | ||
+ | If a second HString with the same characters is created and registered both references point to the same HString. The comparison of two HStrings is way more efficient than with '' | ||
+ | |||
+ | **An example:** | ||
+ | <code java> | ||
+ | HString firstString = HString.getRegisteredHString(" | ||
+ | HString secondString = HString.getRegisteredHString(" | ||
+ | if(firstString == secondString) { | ||
+ | // ... | ||
+ | } | ||
+ | </ | ||
+ | It's possible to compare to non-registered HStrings as well as comparing a registered with a non-registered HString. For this the class HString contains the method //equals//. | ||
+ | <code java> | ||
+ | HString firstString = HString.getRegisteredHString(" | ||
+ | HString secondString = HString.getHString(" | ||
+ | firstString == secondString // evalutes to false | ||
+ | firstString.equals(secondString) // evalutes to true | ||
+ | </ |