diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2021-11-04 15:42:16 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2021-11-04 16:57:37 +0100 |
commit | 393d8629be64fc01271fd746938bb822020f64b9 (patch) | |
tree | 41fcf2357dab739a6492d77146117823ca17df67 /wizards | |
parent | a04d60ca5af1b794c190fa9d5a0fb7506755f27d (diff) |
ScriptForge - (SF_Calc) _ParseAddress() reuse last parsed address
Implementation to improve performance of a simple
cache of the last already parsed range.
The address is reused when the sheet name is explicit and that
the range to parse, as a string, is identical to the
previous parsing request.
Change-Id: I0137689e9697686e76e07e037129983baba6ecfb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124711
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/source/sfdocuments/SF_Base.xba | 2 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Calc.xba | 24 |
2 files changed, 22 insertions, 4 deletions
diff --git a/wizards/source/sfdocuments/SF_Base.xba b/wizards/source/sfdocuments/SF_Base.xba index ae2a23e9f0d3..efdc57be9b4d 100644 --- a/wizards/source/sfdocuments/SF_Base.xba +++ b/wizards/source/sfdocuments/SF_Base.xba @@ -604,8 +604,6 @@ Public Function SetPrinter(Optional ByVal FormDocument As Variant _ ''' PaperFormat: one of next values ''' "A3", "A4", "A5", "B4", "B5", "LETTER", "LEGAL", "TABLOID" ''' Left unchanged when absent -''' _PrintComponent: undocumented argument to determine the component -''' Useful typically to apply printer settings on a Base form document ''' Returns: ''' True when successful ''' Examples: diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index 38ef4e843cef..96dd08d5562c 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -111,6 +111,8 @@ Type _Address XCellRange As Object ' com.sun.star.table.XCellRange End Type +Private _LastParsedAddress As Object ' _Address type - parsed ranges are cached + REM ============================================================ MODULE CONSTANTS Private Const cstSHEET = 1 @@ -135,6 +137,7 @@ Private Sub Class_Initialize() ObjectType = "CALC" ServiceName = "SFDocuments.Calc" Set _Component = Nothing + Set _LastParsedAddress = Nothing End Sub ' SFDocuments.SF_Calc Constructor REM ----------------------------------------------------------------------------- @@ -3379,7 +3382,7 @@ Private Function _ParseAddress(ByVal psAddress As String) As Object ''' Exceptions: ''' CALCADDRESSERROR ' Address could not be parsed to a valid address -Dim oAddress As _Address ' Return value +Dim oAddress As Object ' Return value Dim lStart As Long ' Position of found regex Dim sSheet As String ' Sheet component Dim sRange As String ' Range component @@ -3389,6 +3392,20 @@ Dim oRangeAddress As Object ' Alias for rangeaddress Dim vLastCell As Variant ' Result of _LastCell() method Dim oSelect As Object ' Current selection + ' If psAddress has already been parsed, get the result back + If Not IsNull(_LastParsedAddress) Then + ' Given argument must contain an explicit reference to a sheet + If (InStr(psAddress, "~.") = 0 And InStr(psAddress, ".") > 0 And psAddress = _LastParsedAddress.RawAddress) _ + Or psAddress = _LastParsedAddress.RangeName Then + Set _ParseAddress = _LastParsedAddress + Exit Function + Else + Set _LastParsedAddress = Nothing + End If + End If + + ' Reinitialize a new _Address object + Set oAddress = New _Address With oAddress sSheet = "" : sRange = "" .SheetName = "" : .RangeName = "" @@ -3477,6 +3494,9 @@ Dim oSelect As Object ' Current selection End With + ' Store last parsed address for reuse + Set _LastParsedAddress = oAddress + Finally: Set _ParseAddress = oAddress Exit Function @@ -3736,4 +3756,4 @@ CatchDuplicate: End Function ' SFDocuments.SF_Calc._ValidateSheet REM ============================================ END OF SFDOCUMENTS.SF_CALC -</script:module> +</script:module>
\ No newline at end of file |