Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
G
glog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
glog
Commits
4544e968
Commit
4544e968
authored
Apr 30, 2016
by
dimhotepus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache strlen outside of cycles (PVS-Studio)
parent
de6149ef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
logging_unittest.cc
src/logging_unittest.cc
+4
-3
No files found.
src/logging_unittest.cc
View file @
4544e968
...
...
@@ -768,17 +768,18 @@ static void TestOneTruncate(const char *path, int64 limit, int64 keep,
CHECK_ERR
(
fd
=
open
(
path
,
O_RDWR
|
O_CREAT
|
O_TRUNC
,
0600
));
const
char
*
discardstr
=
"DISCARDME!"
,
*
keepstr
=
"KEEPME!"
;
const
size_t
discard_size
=
strlen
(
discardstr
),
keep_size
=
strlen
(
keepstr
);
// Fill the file with the requested data; first discard data, then kept data
int64
written
=
0
;
while
(
written
<
dsize
)
{
int
bytes
=
min
<
int64
>
(
dsize
-
written
,
strlen
(
discardstr
)
);
int
bytes
=
min
<
int64
>
(
dsize
-
written
,
discard_size
);
CHECK_ERR
(
write
(
fd
,
discardstr
,
bytes
));
written
+=
bytes
;
}
written
=
0
;
while
(
written
<
ksize
)
{
int
bytes
=
min
<
int64
>
(
ksize
-
written
,
strlen
(
keepstr
)
);
int
bytes
=
min
<
int64
>
(
ksize
-
written
,
keep_size
);
CHECK_ERR
(
write
(
fd
,
keepstr
,
bytes
));
written
+=
bytes
;
}
...
...
@@ -800,7 +801,7 @@ static void TestOneTruncate(const char *path, int64 limit, int64 keep,
const
char
*
p
=
buf
;
int64
checked
=
0
;
while
(
checked
<
expect
)
{
int
bytes
=
min
<
int64
>
(
expect
-
checked
,
strlen
(
keepstr
)
);
int
bytes
=
min
<
int64
>
(
expect
-
checked
,
keep_size
);
CHECK
(
!
memcmp
(
p
,
keepstr
,
bytes
));
checked
+=
bytes
;
}
...
...
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