Replace Position::fEndOffset with fLength.
In a followup, this will make it easier to save memory. Change-Id: I33e9838d1b3170362f4e7c58ba5f60a1928a4b55 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/533698 Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
parent
32902b3c82
commit
afa53f2e0b
@ -11,23 +11,19 @@
|
||||
#include "include/core/SkTypes.h"
|
||||
#include <string_view>
|
||||
|
||||
#ifndef __has_builtin
|
||||
#define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
namespace SkSL {
|
||||
|
||||
class Position {
|
||||
public:
|
||||
Position()
|
||||
: fStartOffset(-1)
|
||||
, fEndOffset(-1) {}
|
||||
, fLength(0) {}
|
||||
|
||||
static Position Range(int startOffset, int endOffset) {
|
||||
SkASSERT(startOffset <= endOffset);
|
||||
Position result;
|
||||
result.fStartOffset = startOffset;
|
||||
result.fEndOffset = endOffset;
|
||||
result.fLength = endOffset - startOffset;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -44,12 +40,12 @@ public:
|
||||
|
||||
int endOffset() const {
|
||||
SkASSERT(this->valid());
|
||||
return fEndOffset;
|
||||
return fStartOffset + fLength;
|
||||
}
|
||||
|
||||
// Returns the position from this through, and including the entirety of, end.
|
||||
Position rangeThrough(Position end) const {
|
||||
if (fEndOffset == -1 || end.fEndOffset == -1) {
|
||||
if (fStartOffset == -1 || end.fStartOffset == -1) {
|
||||
return *this;
|
||||
}
|
||||
SkASSERTF(this->startOffset() <= end.startOffset() && this->endOffset() <= end.endOffset(),
|
||||
@ -60,11 +56,12 @@ public:
|
||||
|
||||
// Returns a position representing the character immediately after this position
|
||||
Position after() const {
|
||||
return Range(fEndOffset, fEndOffset + 1);
|
||||
int endOffset = this->endOffset();
|
||||
return Range(endOffset, endOffset + 1);
|
||||
}
|
||||
|
||||
bool operator==(const Position& other) const {
|
||||
return fStartOffset == other.fStartOffset && fEndOffset == other.fEndOffset;
|
||||
return fStartOffset == other.fStartOffset && fLength == other.fLength;
|
||||
}
|
||||
|
||||
bool operator!=(const Position& other) const {
|
||||
@ -89,7 +86,7 @@ public:
|
||||
|
||||
private:
|
||||
int32_t fStartOffset;
|
||||
int32_t fEndOffset;
|
||||
uint32_t fLength;
|
||||
};
|
||||
|
||||
struct ForLoopPositions {
|
||||
|
@ -13,8 +13,8 @@ namespace SkSL {
|
||||
|
||||
int Position::line(std::string_view source) const {
|
||||
SkASSERT(this->valid());
|
||||
if (fEndOffset == -1) {
|
||||
return fStartOffset;
|
||||
if (fStartOffset == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (!source.data()) {
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user