V8 Project
v8::internal::Differencer Class Reference
+ Collaboration diagram for v8::internal::Differencer:

Classes

class  ResultWriter
 

Public Member Functions

 Differencer (Comparator::Input *input)
 
 ~Differencer ()
 
void Initialize ()
 
void FillTable ()
 
void SaveResult (Comparator::Output *chunk_writer)
 

Private Types

enum  Direction {
  EQ = 0 , SKIP1 , SKIP2 , SKIP_ANY ,
  MAX_DIRECTION_FLAG_VALUE = SKIP_ANY
}
 

Private Member Functions

int CompareUpToTail (int pos1, int pos2)
 
intget_cell (int i1, int i2)
 
void set_value4_and_dir (int i1, int i2, int value4, Direction dir)
 
int get_value4 (int i1, int i2)
 
Direction get_direction (int i1, int i2)
 
void StaticAssertHolder ()
 

Private Attributes

Comparator::Inputinput_
 
intbuffer_
 
int len1_
 
int len2_
 

Static Private Attributes

static const int kDirectionSizeBits = 2
 
static const int kDirectionMask = (1 << kDirectionSizeBits) - 1
 
static const int kEmptyCellValue = ~0u << kDirectionSizeBits
 

Detailed Description

Definition at line 39 of file liveedit.cc.

Member Enumeration Documentation

◆ Direction

Enumerator
EQ 
SKIP1 
SKIP2 
SKIP_ANY 
MAX_DIRECTION_FLAG_VALUE 

Definition at line 109 of file liveedit.cc.

Constructor & Destructor Documentation

◆ Differencer()

v8::internal::Differencer::Differencer ( Comparator::Input input)
inlineexplicit

Definition at line 41 of file liveedit.cc.

42  : input_(input), len1_(input->GetLength1()), len2_(input->GetLength2()) {
43  buffer_ = NewArray<int>(len1_ * len2_);
44  }
Comparator::Input * input_
Definition: liveedit.cc:104

References buffer_, len1_, and len2_.

◆ ~Differencer()

v8::internal::Differencer::~Differencer ( )
inline

Definition at line 45 of file liveedit.cc.

45  {
47  }
void DeleteArray(T *array)
Definition: allocation.h:68

References buffer_, and v8::internal::DeleteArray().

+ Here is the call graph for this function:

Member Function Documentation

◆ CompareUpToTail()

int v8::internal::Differencer::CompareUpToTail ( int  pos1,
int  pos2 
)
inlineprivate

Definition at line 120 of file liveedit.cc.

120  {
121  if (pos1 < len1_) {
122  if (pos2 < len2_) {
123  int cached_res = get_value4(pos1, pos2);
124  if (cached_res == kEmptyCellValue) {
125  Direction dir;
126  int res;
127  if (input_->Equals(pos1, pos2)) {
128  res = CompareUpToTail(pos1 + 1, pos2 + 1);
129  dir = EQ;
130  } else {
131  int res1 = CompareUpToTail(pos1 + 1, pos2) +
132  (1 << kDirectionSizeBits);
133  int res2 = CompareUpToTail(pos1, pos2 + 1) +
134  (1 << kDirectionSizeBits);
135  if (res1 == res2) {
136  res = res1;
137  dir = SKIP_ANY;
138  } else if (res1 < res2) {
139  res = res1;
140  dir = SKIP1;
141  } else {
142  res = res2;
143  dir = SKIP2;
144  }
145  }
146  set_value4_and_dir(pos1, pos2, res, dir);
147  cached_res = res;
148  }
149  return cached_res;
150  } else {
151  return (len1_ - pos1) << kDirectionSizeBits;
152  }
153  } else {
154  return (len2_ - pos2) << kDirectionSizeBits;
155  }
156  }
virtual bool Equals(int index1, int index2)=0
static const int kDirectionSizeBits
Definition: liveedit.cc:175
int get_value4(int i1, int i2)
Definition: liveedit.cc:168
int CompareUpToTail(int pos1, int pos2)
Definition: liveedit.cc:120
void set_value4_and_dir(int i1, int i2, int value4, Direction dir)
Definition: liveedit.cc:163
static const int kEmptyCellValue
Definition: liveedit.cc:177

References EQ, v8::internal::Comparator::Input::Equals(), get_value4(), input_, kDirectionSizeBits, kEmptyCellValue, len1_, len2_, set_value4_and_dir(), SKIP1, SKIP2, and SKIP_ANY.

Referenced by FillTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FillTable()

void v8::internal::Differencer::FillTable ( )
inline

Definition at line 58 of file liveedit.cc.

58  {
59  CompareUpToTail(0, 0);
60  }

References CompareUpToTail().

Referenced by v8::internal::Comparator::CalculateDifference().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_cell()

int& v8::internal::Differencer::get_cell ( int  i1,
int  i2 
)
inlineprivate

Definition at line 158 of file liveedit.cc.

158  {
159  return buffer_[i1 + i2 * len1_];
160  }

References buffer_, and len1_.

Referenced by get_direction(), get_value4(), and set_value4_and_dir().

+ Here is the caller graph for this function:

◆ get_direction()

Direction v8::internal::Differencer::get_direction ( int  i1,
int  i2 
)
inlineprivate

Definition at line 171 of file liveedit.cc.

171  {
172  return static_cast<Direction>(get_cell(i1, i2) & kDirectionMask);
173  }
int & get_cell(int i1, int i2)
Definition: liveedit.cc:158
static const int kDirectionMask
Definition: liveedit.cc:176

References get_cell(), and kDirectionMask.

Referenced by SaveResult().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_value4()

int v8::internal::Differencer::get_value4 ( int  i1,
int  i2 
)
inlineprivate

Definition at line 168 of file liveedit.cc.

168  {
169  return get_cell(i1, i2) & (kMaxUInt32 ^ kDirectionMask);
170  }
const uint32_t kMaxUInt32
Definition: globals.h:120

References get_cell(), kDirectionMask, and v8::internal::kMaxUInt32.

Referenced by CompareUpToTail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Initialize()

void v8::internal::Differencer::Initialize ( )
inline

Definition at line 49 of file liveedit.cc.

49  {
50  int array_size = len1_ * len2_;
51  for (int i = 0; i < array_size; i++) {
53  }
54  }

References buffer_, kEmptyCellValue, len1_, and len2_.

Referenced by v8::internal::Comparator::CalculateDifference().

+ Here is the caller graph for this function:

◆ SaveResult()

void v8::internal::Differencer::SaveResult ( Comparator::Output chunk_writer)
inline

Definition at line 62 of file liveedit.cc.

62  {
63  ResultWriter writer(chunk_writer);
64 
65  int pos1 = 0;
66  int pos2 = 0;
67  while (true) {
68  if (pos1 < len1_) {
69  if (pos2 < len2_) {
70  Direction dir = get_direction(pos1, pos2);
71  switch (dir) {
72  case EQ:
73  writer.eq();
74  pos1++;
75  pos2++;
76  break;
77  case SKIP1:
78  writer.skip1(1);
79  pos1++;
80  break;
81  case SKIP2:
82  case SKIP_ANY:
83  writer.skip2(1);
84  pos2++;
85  break;
86  default:
87  UNREACHABLE();
88  }
89  } else {
90  writer.skip1(len1_ - pos1);
91  break;
92  }
93  } else {
94  if (len2_ != pos2) {
95  writer.skip2(len2_ - pos2);
96  }
97  break;
98  }
99  }
100  writer.close();
101  }
Direction get_direction(int i1, int i2)
Definition: liveedit.cc:171
#define UNREACHABLE()
Definition: logging.h:30

References v8::internal::Differencer::ResultWriter::close(), EQ, v8::internal::Differencer::ResultWriter::eq(), get_direction(), len1_, len2_, SKIP1, v8::internal::Differencer::ResultWriter::skip1(), SKIP2, v8::internal::Differencer::ResultWriter::skip2(), SKIP_ANY, and UNREACHABLE.

Referenced by v8::internal::Comparator::CalculateDifference().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_value4_and_dir()

void v8::internal::Differencer::set_value4_and_dir ( int  i1,
int  i2,
int  value4,
Direction  dir 
)
inlineprivate

Definition at line 163 of file liveedit.cc.

163  {
164  DCHECK((value4 & kDirectionMask) == 0);
165  get_cell(i1, i2) = value4 | dir;
166  }
#define DCHECK(condition)
Definition: logging.h:205

References DCHECK, get_cell(), and kDirectionMask.

Referenced by CompareUpToTail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StaticAssertHolder()

void v8::internal::Differencer::StaticAssertHolder ( )
inlineprivate

Definition at line 181 of file liveedit.cc.

181  {
183  }
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))

References kDirectionSizeBits, MAX_DIRECTION_FLAG_VALUE, and v8::internal::STATIC_ASSERT().

+ Here is the call graph for this function:

Member Data Documentation

◆ buffer_

int* v8::internal::Differencer::buffer_
private

Definition at line 105 of file liveedit.cc.

Referenced by Differencer(), get_cell(), Initialize(), and ~Differencer().

◆ input_

Comparator::Input* v8::internal::Differencer::input_
private

Definition at line 104 of file liveedit.cc.

Referenced by CompareUpToTail().

◆ kDirectionMask

const int v8::internal::Differencer::kDirectionMask = (1 << kDirectionSizeBits) - 1
staticprivate

Definition at line 176 of file liveedit.cc.

Referenced by get_direction(), get_value4(), and set_value4_and_dir().

◆ kDirectionSizeBits

const int v8::internal::Differencer::kDirectionSizeBits = 2
staticprivate

Definition at line 175 of file liveedit.cc.

Referenced by CompareUpToTail(), and StaticAssertHolder().

◆ kEmptyCellValue

const int v8::internal::Differencer::kEmptyCellValue = ~0u << kDirectionSizeBits
staticprivate

Definition at line 177 of file liveedit.cc.

Referenced by CompareUpToTail(), and Initialize().

◆ len1_

int v8::internal::Differencer::len1_
private

Definition at line 106 of file liveedit.cc.

Referenced by CompareUpToTail(), Differencer(), get_cell(), Initialize(), and SaveResult().

◆ len2_

int v8::internal::Differencer::len2_
private

Definition at line 107 of file liveedit.cc.

Referenced by CompareUpToTail(), Differencer(), Initialize(), and SaveResult().


The documentation for this class was generated from the following file: