Revision: ae733ec6e430 Branch: rt2036-findPerformance Author: cmyers@xxxxxxxxxxxxxxxxxxxxx Date: Thu Feb 12 15:20:57 2015 UTCLog: Sped up by saving text outside of loop. Need to fix issue - can't search whole document.
https://code.google.com/p/brailleblaster/source/detail?r=ae733ec6e430 Modified: /src/main/org/brailleblaster/search/SearchDialog.java =======================================--- /src/main/org/brailleblaster/search/SearchDialog.java Mon Feb 9 20:59:13 2015 UTC +++ /src/main/org/brailleblaster/search/SearchDialog.java Thu Feb 12 15:20:57 2015 UTC
@@ -807,8 +807,7 @@// /////////////////////////////////////////////////////////////////////////////////
// Define our find button. Button findBtn = new Button(shlFindreplace, SWT.NONE); - findBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, - 3, 1));+ findBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
// formToolkit.adapt(btnFind, true, true); findBtn.setText("Find"); shlFindreplace.setDefaultButton(findBtn); @@ -844,8 +843,7 @@ }); // btnFind.addSelectionListener() Button replaceFindBtn = new Button(shlFindreplace, SWT.NONE); - replaceFindBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, - false, 1, 1));+ replaceFindBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
// formToolkit.adapt(btnReplacefind, true, true); replaceFindBtn.setText("Replace/Find"); replaceFindBtn.setEnabled(false); @@ -1421,6 +1419,9 @@ // Grab text view. TextView tv = man.getText(); + // The text in the view. + String textStr = tv.view.getText(); + // Are there any characters in the text view? If there // are no characters, we probably don't have a document // loaded yet. @@ -1431,7 +1432,7 @@ String findMeStr = searchCombo.getText(); // Get number of characters in text view. - int numChars = tv.view.getText().length(); + int numChars = textStr.length(); // If the search string is larger than the total number of // characters in the view, don't bother. @@ -1459,7 +1460,7 @@ // Scour the view for the search string. while (startCharIndex < numChars && endCharIndex < (numChars + 1)) { // Get current snippet of text we're testing. - String curViewSnippet = tv.view.getText().substring(startCharIndex, + String curViewSnippet = textStr.substring(startCharIndex, endCharIndex); // Should we be checking case sensitive version? @@ -1475,12 +1476,12 @@ if (searchWholeWord == SCH_WHOLE_ON) { // "^[\pL\pN]*$"; if (startCharIndex - 1 >= 0) - if (tv.view.getText() + if (textStr .substring(startCharIndex - 1, startCharIndex) .matches("^[\\pL\\pN]*$") == true) haveAmatch = false; if (endCharIndex + 1 < numChars) - if (tv.view.getText() + if (textStr .substring(endCharIndex, endCharIndex + 1) .matches("^[\\pL\\pN]*$") == true) haveAmatch = false; @@ -1540,6 +1541,9 @@ // Returns true if one was found. // Grab text view. TextView tv = man.getText(); + + // The text in the view. + String textStr = tv.view.getText(); // Are there any characters in the text view? If there // are no characters, we probably don't have a document @@ -1550,9 +1554,8 @@ // Grab search string. String findMeStr = searchCombo.getText(); - // Get number of characters in text view. - int numChars = tv.view.getText().length(); + int numChars = textStr.length(); // If the search string is larger than the total number of // characters in the view, don't bother. @@ -1566,8 +1569,7 @@ // Scour the view for the search string. while (startCharIndex < numChars && endCharIndex < (numChars + 1)) { // Get current snippet of text we're testing. - String curViewSnippet = tv.view.getText().substring(startCharIndex, - endCharIndex); + String curViewSnippet = textStr.substring(startCharIndex, endCharIndex); // Should we be checking case sensitive version? if (searchCaseSensitive == SCH_CASE_OFF) { @@ -1582,14 +1584,10 @@ if (searchWholeWord == SCH_WHOLE_ON) { // "^[\pL\pN]*$"; if (startCharIndex - 1 >= 0) - if (tv.view.getText() - .substring(startCharIndex - 1, startCharIndex) - .matches("^[\\pL\\pN]*$") == true)+ if (textStr.substring(startCharIndex - 1, startCharIndex).matches("^[\\pL\\pN]*$") == true)
haveAmatch = false; if (endCharIndex + 1 < numChars) - if (tv.view.getText() - .substring(endCharIndex, endCharIndex + 1) - .matches("^[\\pL\\pN]*$") == true)+ if (textStr.substring(endCharIndex, endCharIndex + 1).matches("^[\\pL\\pN]*$") == true)
haveAmatch = false; } // if( searchWholeWord...