From 8b0254a1fa3ad5bf336ff06f22a0264c7257e80a Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Tue, 13 Aug 2002 17:30:23 +0000 Subject: [PATCH] Optimize RegExp code by using 'test' instead of 'match'. b=145373, fix by neil@parkwaycc.co.uk, r=cmanske, sr=alecf git-svn-id: svn://10.0.0.236/trunk@127179 18797224-902f-48f8-a5cc-f745e15eee43 --- .../editor/ui/dialogs/content/EdColorProps.js | 2 +- .../ui/dialogs/content/EdConvertToTable.js | 8 +++--- .../ui/dialogs/content/EdDialogCommon.js | 25 +++++-------------- .../editor/ui/dialogs/content/EdHLineProps.js | 9 ++++--- .../ui/dialogs/content/EdImageOverlay.js | 5 ++-- .../editor/ui/dialogs/content/EdLabelProps.js | 2 +- .../editor/ui/dialogs/content/EdReplace.js | 5 ++-- 7 files changed, 21 insertions(+), 35 deletions(-) diff --git a/mozilla/editor/ui/dialogs/content/EdColorProps.js b/mozilla/editor/ui/dialogs/content/EdColorProps.js index 6508ed0bf7b..571cb682eb3 100644 --- a/mozilla/editor/ui/dialogs/content/EdColorProps.js +++ b/mozilla/editor/ui/dialogs/content/EdColorProps.js @@ -117,7 +117,7 @@ function InitDialog() { // Get image from document gBackgroundImage = GetHTMLOrCSSStyleValue(globalElement, backgroundStr, cssBackgroundImageStr); - if (gBackgroundImage.match( /url\((.*)\)/ )) + if (/url\((.*)\)/.test( gBackgroundImage )) gBackgroundImage = RegExp.$1; gDialog.BackgroundImageInput.value = gBackgroundImage; diff --git a/mozilla/editor/ui/dialogs/content/EdConvertToTable.js b/mozilla/editor/ui/dialogs/content/EdConvertToTable.js index 19c75b7180a..c9dbc82807c 100644 --- a/mozilla/editor/ui/dialogs/content/EdConvertToTable.js +++ b/mozilla/editor/ui/dialogs/content/EdConvertToTable.js @@ -150,7 +150,7 @@ function onAccept() { var tagContent = TrimString(str.slice(start+1, end)); - if ( tagContent.match(/^ol|^ul|^dl/) ) + if ( /^ol|^ul|^dl/.test(tagContent) ) { // Replace list tag with
to start new row // at begining of second or greater list tag @@ -161,7 +161,7 @@ function onAccept() // Reset for list item separation into cells listItemSeparator = ""; } - else if ( tagContent.match(/^li|^dt|^dd/) ) + else if ( /^li|^dt|^dd/.test(tagContent) ) { // Start a new row if this is first item after the ending the last list if (endList) @@ -178,8 +178,8 @@ function onAccept() else { // Find end tags - endList = tagContent.match(/^\/ol|^\/ul|^\/dl/); - if ( endList || tagContent.match(/^\/li|^\/dt|^\/dd/) ) + endList = /^\/ol|^\/ul|^\/dl/.test(tagContent); + if ( endList || /^\/li|^\/dt|^\/dd/.test(tagContent) ) { // Strip out tag str = str.slice(0, start) + str.slice(end+1); diff --git a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js index 56b33e51f5f..cad77a67a7e 100644 --- a/mozilla/editor/ui/dialogs/content/EdDialogCommon.js +++ b/mozilla/editor/ui/dialogs/content/EdDialogCommon.js @@ -336,16 +336,6 @@ function LimitStringLength(elementID, length) editField.value = stringIn.slice(0,length); } -function StripPxUnit(value) -{ - var pxIndex = value.search(/px/); - if (pxIndex > 0) { - // Strip out the unit - value = value.substr(0, pxIndex); - } - return value; -} - function InitPixelOrPercentMenulist(elementForAtt, elementInDoc, attribute, menulistID, defaultIndex) { if (!defaultIndex) defaultIndex = gPixel; @@ -371,23 +361,20 @@ function InitPixelOrPercentMenulist(elementForAtt, elementInDoc, attribute, menu if (size && size.length > 0) { // Search for a "%" or "px" - var percentIndex = size.search(/%/); - var pxIndex = size.search(/px/); - if (percentIndex > 0) + if (/%/.test(size)) { // Strip out the % - size = size.substr(0, percentIndex); + size = RegExp.leftContext; if (percentItem) menulist.selectedItem = percentItem; } - else if (pxIndex > 0) + else { - // Strip out the % - size = size.substr(0, pxIndex); + if (/px/.test(size)) + // Strip out the px + size = RegExp.leftContext; menulist.selectedItem = pixelItem; } - else - menulist.selectedItem = pixelItem; } else menulist.selectedIndex = defaultIndex; diff --git a/mozilla/editor/ui/dialogs/content/EdHLineProps.js b/mozilla/editor/ui/dialogs/content/EdHLineProps.js index f02f79f2cd5..5e49bf27676 100644 --- a/mozilla/editor/ui/dialogs/content/EdHLineProps.js +++ b/mozilla/editor/ui/dialogs/content/EdHLineProps.js @@ -74,7 +74,9 @@ function InitDialog() // Just to be confusing, "size" is used instead of height because it does // not accept % values, only pixels var height = GetHTMLOrCSSStyleValue(globalElement, "size", "height") - height = StripPxUnit(height); + if (/px/.test(height)) { + height = RegExp.leftContext; + } if(!height) { height = 2; //Default value } @@ -124,16 +126,15 @@ function onSaveDefault() } prefs.setIntPref("editor.hrule.align", alignInt); - var percentIndex = width.search(/%/); var percent; var widthInt; var heightInt; if (width) { - if (percentIndex > 0) { + if (/%/.test(width)) { percent = true; - widthInt = Number(width.substr(0, percentIndex)); + widthInt = Number(RegExp.leftContext); } else { percent = false; widthInt = Number(width); diff --git a/mozilla/editor/ui/dialogs/content/EdImageOverlay.js b/mozilla/editor/ui/dialogs/content/EdImageOverlay.js index 0f6e78d9e6b..92a2608c5cb 100644 --- a/mozilla/editor/ui/dialogs/content/EdImageOverlay.js +++ b/mozilla/editor/ui/dialogs/content/EdImageOverlay.js @@ -139,11 +139,10 @@ function InitImage() // dialog.border.value = globalElement.getAttribute("border"); var bv = GetHTMLOrCSSStyleValue(globalElement, "border", "border-top-width"); - var pxIndex = bv.search(/px/); - if (pxIndex > 0) + if (/px/.test(bv)) { // Strip out the px - bv = bv.substr(0, pxIndex); + bv = RegExp.leftContext; } else if (bv == "thin") { diff --git a/mozilla/editor/ui/dialogs/content/EdLabelProps.js b/mozilla/editor/ui/dialogs/content/EdLabelProps.js index 332ec437e19..abc40e56863 100644 --- a/mozilla/editor/ui/dialogs/content/EdLabelProps.js +++ b/mozilla/editor/ui/dialogs/content/EdLabelProps.js @@ -57,7 +57,7 @@ function Startup() editorShell.SelectElement(labelElement); gDialog.labelText.value = GetSelectionAsText(); - if (labelElement.innerHTML.match(/