Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
onlyoffice_core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
onlyoffice_core
Commits
c8c5b829
Commit
c8c5b829
authored
Jan 19, 2017
by
Oleg Korshul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cashed scripts data scheme (may be disable)
parent
2e99efee
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
186 additions
and
6 deletions
+186
-6
DesktopEditor/common/File.h
DesktopEditor/common/File.h
+47
-0
DesktopEditor/doctrenderer/docbuilder_p.h
DesktopEditor/doctrenderer/docbuilder_p.h
+51
-3
DesktopEditor/doctrenderer/doctrenderer.cpp
DesktopEditor/doctrenderer/doctrenderer.cpp
+23
-3
DesktopEditor/doctrenderer/nativecontrol.h
DesktopEditor/doctrenderer/nativecontrol.h
+65
-0
No files found.
DesktopEditor/common/File.h
View file @
c8c5b829
...
...
@@ -1185,6 +1185,53 @@ namespace NSFile
}
return
sPath
;
}
// CommonFunctions
static
std
::
wstring
GetFileExtention
(
const
std
::
wstring
&
sPath
)
{
std
::
wstring
::
size_type
nPos
=
sPath
.
rfind
(
'.'
);
if
(
nPos
!=
std
::
wstring
::
npos
)
return
sPath
.
substr
(
nPos
+
1
);
return
sPath
;
}
static
std
::
wstring
GetFileName
(
const
std
::
wstring
&
sPath
)
{
std
::
wstring
::
size_type
nPos1
=
sPath
.
rfind
(
'\\'
);
std
::
wstring
::
size_type
nPos2
=
sPath
.
rfind
(
'/'
);
std
::
wstring
::
size_type
nPos
=
std
::
wstring
::
npos
;
if
(
nPos1
!=
std
::
wstring
::
npos
)
{
nPos
=
nPos1
;
if
(
nPos2
!=
std
::
wstring
::
npos
&&
nPos2
>
nPos
)
nPos
=
nPos2
;
}
else
nPos
=
nPos2
;
if
(
nPos
==
std
::
wstring
::
npos
)
return
sPath
;
return
sPath
.
substr
(
nPos
+
1
);
}
static
std
::
wstring
GetDirectoryName
(
const
std
::
wstring
&
sPath
)
{
std
::
wstring
::
size_type
nPos1
=
sPath
.
rfind
(
'\\'
);
std
::
wstring
::
size_type
nPos2
=
sPath
.
rfind
(
'/'
);
std
::
wstring
::
size_type
nPos
=
std
::
wstring
::
npos
;
if
(
nPos1
!=
std
::
wstring
::
npos
)
{
nPos
=
nPos1
;
if
(
nPos2
!=
std
::
wstring
::
npos
&&
nPos2
>
nPos
)
nPos
=
nPos2
;
}
else
nPos
=
nPos2
;
if
(
nPos
==
std
::
wstring
::
npos
)
return
sPath
;
return
sPath
.
substr
(
0
,
nPos
);
}
}
#endif //_BUILD_FILE_CROSSPLATFORM_H_
DesktopEditor/doctrenderer/docbuilder_p.h
View file @
c8c5b829
...
...
@@ -172,7 +172,7 @@ public:
return
true
;
}
bool
OpenFile
(
const
std
::
wstring
&
sBasePath
,
const
std
::
wstring
&
path
,
const
std
::
string
&
sString
)
bool
OpenFile
(
const
std
::
wstring
&
sBasePath
,
const
std
::
wstring
&
path
,
const
std
::
string
&
sString
,
const
std
::
wstring
&
sCachePath
)
{
LOGGER_SPEED_START
...
...
@@ -181,7 +181,15 @@ public:
v8
::
TryCatch
try_catch
;
v8
::
Local
<
v8
::
String
>
source
=
v8
::
String
::
NewFromUtf8
(
m_isolate
,
sString
.
c_str
());
v8
::
Local
<
v8
::
Script
>
script
=
v8
::
Script
::
Compile
(
source
);
v8
::
Local
<
v8
::
Script
>
script
;
CCacheDataScript
oCachedScript
(
sCachePath
);
if
(
sCachePath
.
empty
())
script
=
v8
::
Script
::
Compile
(
source
);
else
{
script
=
oCachedScript
.
Compile
(
m_context
,
source
);
}
LOGGER_SPEED_LAP
(
"compile"
)
...
...
@@ -463,6 +471,8 @@ namespace NSDoctRenderer
CDocBuilderParams
m_oParams
;
bool
m_bIsInit
;
bool
m_bIsCacheScript
;
public:
CDocBuilder_Private
()
{
...
...
@@ -478,6 +488,7 @@ namespace NSDoctRenderer
m_pAdditionalData
=
NULL
;
m_bIsInit
=
false
;
m_bIsCacheScript
=
true
;
}
void
Init
()
...
...
@@ -1125,7 +1136,11 @@ namespace NSDoctRenderer
m_pWorker
->
m_nFileType
=
m_nFileType
;
m_pWorker
->
m_sUtf8ArgumentJSON
=
m_oParams
.
m_sArgumentJSON
;
bool
bOpen
=
m_pWorker
->
OpenFile
(
m_sX2tPath
,
m_sFileDir
,
GetScript
());
std
::
wstring
sCachePath
=
L""
;
if
(
m_bIsCacheScript
)
sCachePath
=
GetScriptCache
();
bool
bOpen
=
m_pWorker
->
OpenFile
(
m_sX2tPath
,
m_sFileDir
,
GetScript
(),
sCachePath
);
if
(
!
bOpen
)
return
false
;
}
...
...
@@ -1181,6 +1196,37 @@ namespace NSDoctRenderer
return
strScript
;
}
std
::
wstring
GetScriptCache
()
{
std
::
vector
<
std
::
wstring
>*
arSdkFiles
=
NULL
;
switch
(
m_nFileType
)
{
case
0
:
{
arSdkFiles
=
&
m_arDoctSDK
;
break
;
}
case
1
:
{
arSdkFiles
=
&
m_arPpttSDK
;
break
;
}
case
2
:
{
arSdkFiles
=
&
m_arXlstSDK
;
break
;
}
default:
return
L""
;
}
if
(
0
<
arSdkFiles
->
size
())
{
return
NSCommon
::
GetDirectoryName
(
*
arSdkFiles
->
begin
())
+
L"/sdk-all.cache"
;
}
return
L""
;
}
std
::
string
ReadScriptFile
(
const
std
::
wstring
&
strFile
)
{
NSFile
::
CFileBinary
oFile
;
...
...
@@ -1450,6 +1496,8 @@ namespace NSDoctRenderer
m_pInternal
->
m_oParams
.
m_bCheckFonts
=
true
;
else
if
(
sParam
==
"--work-directory"
)
m_pInternal
->
m_oParams
.
m_sWorkDir
=
std
::
wstring
(
value
);
else
if
(
sParam
==
"--cache-scripts"
)
m_pInternal
->
m_bIsCacheScript
=
(
std
::
wstring
(
value
)
==
L"true"
);
else
if
(
sParam
==
"--argument"
)
{
std
::
wstring
sArg
(
value
);
...
...
DesktopEditor/doctrenderer/doctrenderer.cpp
View file @
c8c5b829
...
...
@@ -70,6 +70,8 @@ namespace NSDoctRenderer
bool
m_bIsOnlyOnePage
;
bool
m_bIsCachedScripts
;
public:
CExecuteParams
()
:
m_arChanges
()
{
...
...
@@ -94,6 +96,7 @@ namespace NSDoctRenderer
m_nSaveToPDFParams
=
0
;
m_bIsOnlyOnePage
=
false
;
m_bIsCachedScripts
=
true
;
}
~
CExecuteParams
()
{
...
...
@@ -151,6 +154,9 @@ namespace NSDoctRenderer
if
(
nParams
&
0x02
)
m_nSaveToPDFParams
=
1
;
if
(
nParams
&
0x04
)
m_bIsCachedScripts
=
false
;
m_bIsOnlyOnePage
=
(
oNode
.
ReadValueInt
(
L"OnlyOnePage"
,
0
)
==
1
)
?
true
:
false
;
return
true
;
...
...
@@ -584,7 +590,7 @@ namespace NSDoctRenderer
}
bool
ExecuteScript
(
const
std
::
string
&
strScript
,
std
::
wstring
&
strError
,
std
::
wstring
&
strReturnParams
)
bool
ExecuteScript
(
const
std
::
string
&
strScript
,
const
std
::
wstring
&
sCachePath
,
std
::
wstring
&
strError
,
std
::
wstring
&
strReturnParams
)
{
bool
bIsBreak
=
false
;
v8
::
Isolate
*
isolate
=
CV8Worker
::
getInitializer
()
->
CreateNew
();
...
...
@@ -604,7 +610,15 @@ namespace NSDoctRenderer
v8
::
Context
::
Scope
context_scope
(
context
);
v8
::
TryCatch
try_catch
;
v8
::
Local
<
v8
::
String
>
source
=
v8
::
String
::
NewFromUtf8
(
isolate
,
strScript
.
c_str
());
v8
::
Local
<
v8
::
Script
>
script
=
v8
::
Script
::
Compile
(
source
);
v8
::
Local
<
v8
::
Script
>
script
;
CCacheDataScript
oCachedScript
(
sCachePath
);
if
(
sCachePath
.
empty
())
script
=
v8
::
Script
::
Compile
(
source
);
else
{
script
=
oCachedScript
.
Compile
(
context
,
source
);
}
// COMPILE
if
(
try_catch
.
HasCaught
())
...
...
@@ -1096,8 +1110,14 @@ namespace NSDoctRenderer
strScript
+=
"
\n\n
"
;
}
std
::
wstring
sCachePath
=
L""
;
if
(
NULL
!=
arSdkFiles
)
{
if
(
m_pInternal
->
m_oParams
.
m_bIsCachedScripts
&&
(
0
<
arSdkFiles
->
size
()))
{
sCachePath
=
NSFile
::
GetDirectoryName
(
*
arSdkFiles
->
begin
())
+
L"/sdk-all.cache"
;
}
for
(
std
::
vector
<
std
::
wstring
>::
iterator
i
=
arSdkFiles
->
begin
();
i
!=
arSdkFiles
->
end
();
i
++
)
{
strScript
+=
m_pInternal
->
ReadScriptFile
(
*
i
);
...
...
@@ -1109,7 +1129,7 @@ namespace NSDoctRenderer
strScript
+=
"
\n
$.ready();"
;
std
::
wstring
sReturnParams
=
L""
;
bool
bResult
=
m_pInternal
->
ExecuteScript
(
strScript
,
strError
,
sReturnParams
);
bool
bResult
=
m_pInternal
->
ExecuteScript
(
strScript
,
s
CachePath
,
s
trError
,
sReturnParams
);
if
(
strError
.
length
()
!=
0
)
{
...
...
DesktopEditor/doctrenderer/nativecontrol.h
View file @
c8c5b829
...
...
@@ -977,4 +977,69 @@ bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFi
v8
::
TryCatch
&
try_catch
,
std
::
wstring
&
strError
);
class
CCacheDataScript
{
private:
BYTE
*
Data
;
int
Length
;
v8
::
ScriptCompiler
::
Source
*
Source
;
v8
::
ScriptCompiler
::
CachedData
*
CachedData
;
std
::
wstring
Path
;
public:
CCacheDataScript
(
const
std
::
wstring
&
sPath
)
{
Data
=
NULL
;
Length
=
0
;
if
(
!
sPath
.
empty
())
{
BYTE
*
_data
=
NULL
;
DWORD
_data_length
=
0
;
if
(
NSFile
::
CFileBinary
::
ReadAllBytes
(
sPath
,
&
_data
,
_data_length
))
{
Data
=
_data
;
Length
=
(
int
)
_data_length
;
}
}
Source
=
NULL
;
CachedData
=
NULL
;
Path
=
sPath
;
}
~
CCacheDataScript
()
{
//RELEASEOBJECT(Source);
//RELEASEOBJECT(CachedData);
RELEASEARRAYOBJECTS
(
Data
);
}
v8
::
Local
<
v8
::
Script
>
Compile
(
const
v8
::
Local
<
v8
::
Context
>&
_context
,
const
v8
::
Local
<
v8
::
String
>&
source
)
{
v8
::
Local
<
v8
::
Script
>
script
;
if
(
NULL
==
Data
)
{
Source
=
new
v8
::
ScriptCompiler
::
Source
(
source
);
script
=
v8
::
ScriptCompiler
::
Compile
(
_context
,
Source
,
v8
::
ScriptCompiler
::
kProduceCodeCache
).
ToLocalChecked
();
const
v8
::
ScriptCompiler
::
CachedData
*
_cachedData
=
Source
->
GetCachedData
();
NSFile
::
CFileBinary
oFileTest
;
if
(
oFileTest
.
CreateFileW
(
Path
))
{
oFileTest
.
WriteFile
(
_cachedData
->
data
,
(
DWORD
)
_cachedData
->
length
);
oFileTest
.
CloseFile
();
}
}
else
{
CachedData
=
new
v8
::
ScriptCompiler
::
CachedData
(
Data
,
Length
);
Source
=
new
v8
::
ScriptCompiler
::
Source
(
source
,
CachedData
);
script
=
v8
::
ScriptCompiler
::
Compile
(
_context
,
Source
,
v8
::
ScriptCompiler
::
kConsumeCodeCache
).
ToLocalChecked
();
}
return
script
;
}
};
#endif // NATIVECONTROL
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment