mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some fix
This commit is contained in:
parent
b62bcb5a99
commit
35cb1fba24
@ -196,12 +196,6 @@ struct vector {
|
|||||||
_capacity = cap;
|
_capacity = cap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(int size) {
|
|
||||||
reserve(size);
|
|
||||||
std::uninitialized_default_construct_n(_data + _size, size - _size);
|
|
||||||
_size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void emplace_back(Args&&... args) {
|
void emplace_back(Args&&... args) {
|
||||||
if(_size == _capacity) reserve(_capacity * 2);
|
if(_size == _capacity) reserve(_capacity * 2);
|
||||||
@ -432,7 +426,7 @@ struct small_map {
|
|||||||
Item* data() const { return _data.data(); }
|
Item* data() const { return _data.data(); }
|
||||||
|
|
||||||
void insert(const K& key, const V& value) {
|
void insert(const K& key, const V& value) {
|
||||||
auto it = std::lower_bound(_data.begin(), _data.end(), key);
|
Item* it = std::lower_bound(_data.begin(), _data.end(), key);
|
||||||
assert(it == _data.end() || it->first != key);
|
assert(it == _data.end() || it->first != key);
|
||||||
_data.insert(it, {key, value});
|
_data.insert(it, {key, value});
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ struct _FrameRecord {
|
|||||||
|
|
||||||
struct LineProfiler {
|
struct LineProfiler {
|
||||||
// filename -> records
|
// filename -> records
|
||||||
small_map<std::string_view, vector<_LineRecord>> records;
|
small_map<std::string_view, _LineRecord*> records;
|
||||||
vector<_FrameRecord> frames;
|
vector<_FrameRecord> frames;
|
||||||
vector<FuncDecl*> functions;
|
vector<FuncDecl*> functions;
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ struct LineProfiler {
|
|||||||
void _step_end(int, Frame*, int);
|
void _step_end(int, Frame*, int);
|
||||||
void end();
|
void end();
|
||||||
Str stats();
|
Str stats();
|
||||||
|
~LineProfiler();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pkpy
|
} // namespace pkpy
|
||||||
|
@ -28,14 +28,16 @@ void LineProfiler::_step(int callstack_size, Frame* frame) {
|
|||||||
_step_end(callstack_size, frame, line);
|
_step_end(callstack_size, frame, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& file_records = *records.try_get(filename);
|
_LineRecord* file_records;
|
||||||
if(file_records.empty()) {
|
|
||||||
// initialize file_records
|
auto p = records.try_get(filename);
|
||||||
|
if(p == nullptr) {
|
||||||
int total_lines = frame->co->src->line_starts.size();
|
int total_lines = frame->co->src->line_starts.size();
|
||||||
file_records.resize(total_lines + 1);
|
file_records = new _LineRecord[total_lines + 1];
|
||||||
for(int i = 1; i <= total_lines; i++) {
|
for(int i = 1; i <= total_lines; i++) file_records[i].line = i;
|
||||||
file_records[i].line = i;
|
records.insert(filename, file_records);
|
||||||
}
|
}else{
|
||||||
|
file_records = *p;
|
||||||
}
|
}
|
||||||
|
|
||||||
frames.back().prev_record = &file_records[line];
|
frames.back().prev_record = &file_records[line];
|
||||||
@ -85,8 +87,7 @@ Str LineProfiler::stats() {
|
|||||||
int end_line = decl->code->end_line;
|
int end_line = decl->code->end_line;
|
||||||
if(start_line == -1 || end_line == -1) continue;
|
if(start_line == -1 || end_line == -1) continue;
|
||||||
std::string_view filename = decl->code->src->filename.sv();
|
std::string_view filename = decl->code->src->filename.sv();
|
||||||
vector<_LineRecord>& file_records = *records.try_get(filename);
|
const _LineRecord* file_records = records[filename];
|
||||||
if(file_records.empty()) continue;
|
|
||||||
clock_t total_time = 0;
|
clock_t total_time = 0;
|
||||||
for(int line = start_line; line <= end_line; line++) {
|
for(int line = start_line; line <= end_line; line++) {
|
||||||
total_time += file_records[line].time;
|
total_time += file_records[line].time;
|
||||||
@ -120,4 +121,8 @@ Str LineProfiler::stats() {
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LineProfiler::~LineProfiler() {
|
||||||
|
for(auto& p: records) delete p.second;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pkpy
|
} // namespace pkpy
|
||||||
|
@ -25,8 +25,7 @@ std::string pkpy_platform_getline(bool* eof) {
|
|||||||
}
|
}
|
||||||
std::wstring wideInput = wss.str();
|
std::wstring wideInput = wss.str();
|
||||||
int length = WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), NULL, 0, NULL, NULL);
|
int length = WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), NULL, 0, NULL, NULL);
|
||||||
std::string output;
|
std::string output(length);
|
||||||
output.resize(length);
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), &output[0], length, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), &output[0], length, NULL, NULL);
|
||||||
if(!output.empty() && output.back() == '\r') output.pop_back();
|
if(!output.empty() && output.back() == '\r') output.pop_back();
|
||||||
return output;
|
return output;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user