Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
f78eb27c
Commit
f78eb27c
authored
10 years ago
by
Keisuke Kuroyanagi
Committed by
Android (Google) Code Review
10 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Refactoring checkAndPrepareWriting." into lmp-dev
parents
5a289ed2
6810e8df
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp
+28
-18
28 additions, 18 deletions
...cyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp
with
28 additions
and
18 deletions
native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp
+
28
−
18
View file @
f78eb27c
...
@@ -107,27 +107,37 @@ bool BufferWithExtendableBuffer::extendBuffer() {
...
@@ -107,27 +107,37 @@ bool BufferWithExtendableBuffer::extendBuffer() {
}
}
bool
BufferWithExtendableBuffer
::
checkAndPrepareWriting
(
const
int
pos
,
const
int
size
)
{
bool
BufferWithExtendableBuffer
::
checkAndPrepareWriting
(
const
int
pos
,
const
int
size
)
{
if
(
isInAdditionalBuffer
(
pos
))
{
if
(
pos
<
0
||
size
<
0
)
{
const
int
tailPosition
=
getTailPosition
();
// Invalid position or size.
if
(
pos
==
tailPosition
)
{
return
false
;
// Append data to the tail.
}
if
(
pos
+
size
>
static_cast
<
int
>
(
mAdditionalBuffer
.
size
())
+
mOriginalBufferSize
)
{
const
size_t
totalRequiredSize
=
static_cast
<
size_t
>
(
pos
+
size
);
// Need to extend buffer.
if
(
!
isInAdditionalBuffer
(
pos
))
{
if
(
!
extendBuffer
())
{
// Here don't need to care about the additional buffer.
return
false
;
if
(
static_cast
<
size_t
>
(
mOriginalBufferSize
)
<
totalRequiredSize
)
{
}
// Violate the boundary.
}
mUsedAdditionalBufferSize
+=
size
;
}
else
if
(
pos
+
size
>
tailPosition
)
{
// The access will beyond the tail of used region.
return
false
;
}
}
else
{
if
(
pos
<
0
||
mOriginalBufferSize
<
pos
+
size
)
{
// Invalid position or violate the boundary.
return
false
;
return
false
;
}
}
// The buffer has sufficient capacity.
return
true
;
}
// Hereafter, pos is in the additional buffer.
const
size_t
tailPosition
=
static_cast
<
size_t
>
(
getTailPosition
());
if
(
totalRequiredSize
<=
tailPosition
)
{
// The buffer has sufficient capacity.
return
true
;
}
if
(
static_cast
<
size_t
>
(
pos
)
!=
tailPosition
)
{
// The additional buffer must be extended from the tail position.
return
false
;
}
const
size_t
extendSize
=
totalRequiredSize
-
std
::
min
(
mAdditionalBuffer
.
size
()
+
mOriginalBufferSize
,
totalRequiredSize
);
if
(
extendSize
>
0
&&
!
extendBuffer
())
{
// Failed to extend the buffer.
return
false
;
}
}
mUsedAdditionalBufferSize
+=
size
;
return
true
;
return
true
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment