Pay Less for strings

xiaoxiao2021-03-06  15

This is seen on Eclipsepowered. ED referred to the issue of string # substring and string (string) of Jerome Lanneluc in Eclipse-dev key. According to Jerome, use String # substring (), the space occupied by the original long string is still occupied, and it is not released, using string (String) to solve this problem. Jerome's original text:

I just noticed that String # substring (...) shares the underlying char array. So if you have a big string, take a substring of it, throw away the big string, you will still hold on the big char array. A simple way to Solve this is to make a copy of the substring using the string (string) constructor.

I saved 550KB in JDT Core by changing the following code: ( '.' FullQualifiedName.lastIndexOf ()) String simpleName = fullyQualifiedName.substring; toString simpleName = newString ( '.' FullyQualifiedName.substring (fullQualifiedName.lastIndexOf ()));

After the release of Eclipse3.1, the user found that 3.1 occupied a large number of Heap (about 200-300m). Eclipse's development team is constantly solving this problem, and String # substing improvements will be released in Eclipse 3.1m6 (April 1).

This tip is actually used in our own project.

转载请注明原文地址:https://www.9cbs.com/read-42217.html

New Post(0)