This commit is contained in:
Kovid Goyal
2022-01-03 14:31:16 +05:30
2 changed files with 10 additions and 10 deletions

View File

@@ -111,7 +111,7 @@ add_line(Segment *bg_segment, Segment *fg_segment, LineBuffer *lb, PyObject *ans
return true; return true;
} }
static LineBuffer b; static LineBuffer line_buffer;
static PyObject* static PyObject*
split_with_highlights(PyObject *self UNUSED, PyObject *args) { split_with_highlights(PyObject *self UNUSED, PyObject *args) {
@@ -132,13 +132,13 @@ split_with_highlights(PyObject *self UNUSED, PyObject *args) {
#define NEXT_TRUNCATE_POINT truncate_point = (truncate_pos < num_truncate_pts) ? truncate_points[truncate_pos++] : UINT_MAX #define NEXT_TRUNCATE_POINT truncate_point = (truncate_pos < num_truncate_pts) ? truncate_points[truncate_pos++] : UINT_MAX
NEXT_TRUNCATE_POINT; NEXT_TRUNCATE_POINT;
#define INSERT_CODE(x) { CHECK_CALL(insert_code, x, &b); } #define INSERT_CODE(x) { CHECK_CALL(insert_code, x, &line_buffer); }
#define ADD_LINE CHECK_CALL(add_line, &bg_segment.sg, &fg_segment.sg, &b, ans); #define ADD_LINE CHECK_CALL(add_line, &bg_segment.sg, &fg_segment.sg, &line_buffer, ans);
#define ADD_CHAR(x) { \ #define ADD_CHAR(x) { \
if (!ensure_space(&b, 1)) { Py_CLEAR(ans); return NULL; } \ if (!ensure_space(&line_buffer, 1)) { Py_CLEAR(ans); return NULL; } \
b.buf[b.pos++] = x; \ line_buffer.buf[line_buffer.pos++] = x; \
} }
#define CHECK_SEGMENT(sgp, is_fg) { \ #define CHECK_SEGMENT(sgp, is_fg) { \
if (i == sgp.sg.current_pos) { \ if (i == sgp.sg.current_pos) { \
@@ -157,7 +157,7 @@ split_with_highlights(PyObject *self UNUSED, PyObject *args) {
} }
const unsigned int line_sz = PyUnicode_GET_LENGTH(line); const unsigned int line_sz = PyUnicode_GET_LENGTH(line);
b.pos = 0; line_buffer.pos = 0;
unsigned int i = 0; unsigned int i = 0;
for (; i < line_sz; i++) { for (; i < line_sz; i++) {
if (i == truncate_point) { ADD_LINE; NEXT_TRUNCATE_POINT; } if (i == truncate_point) { ADD_LINE; NEXT_TRUNCATE_POINT; }
@@ -165,7 +165,7 @@ split_with_highlights(PyObject *self UNUSED, PyObject *args) {
CHECK_SEGMENT(fg_segment, true) CHECK_SEGMENT(fg_segment, true)
ADD_CHAR(PyUnicode_READ(PyUnicode_KIND(line), PyUnicode_DATA(line), i)); ADD_CHAR(PyUnicode_READ(PyUnicode_KIND(line), PyUnicode_DATA(line), i));
} }
if (b.pos) ADD_LINE; if (line_buffer.pos) ADD_LINE;
return ans; return ans;
#undef INSERT_CODE #undef INSERT_CODE
#undef CHECK_SEGMENT #undef CHECK_SEGMENT
@@ -177,7 +177,7 @@ split_with_highlights(PyObject *self UNUSED, PyObject *args) {
static void static void
free_resources(void) { free_resources(void) {
free(b.buf); b.buf = NULL; b.capacity = 0; b.pos = 0; free(line_buffer.buf); line_buffer.buf = NULL; line_buffer.capacity = 0; line_buffer.pos = 0;
} }
static PyMethodDef module_methods[] = { static PyMethodDef module_methods[] = {

View File

@@ -85,8 +85,8 @@ update_os_window_viewport(OSWindow *window, bool notify_boss) {
window->viewport_updated_at_least_once = true; window->viewport_updated_at_least_once = true;
window->viewport_width = fw; window->viewport_height = fh; window->viewport_width = fw; window->viewport_height = fh;
double xr = window->viewport_x_ratio, yr = window->viewport_y_ratio; double xr = window->viewport_x_ratio, yr = window->viewport_y_ratio;
window->viewport_x_ratio = w > 0 ? (double)window->viewport_width / (double)w : xr; window->viewport_x_ratio = (double)window->viewport_width / (double)w;
window->viewport_y_ratio = h > 0 ? (double)window->viewport_height / (double)h : yr; window->viewport_y_ratio = (double)window->viewport_height / (double)h;
bool dpi_changed = (xr != 0.0 && xr != window->viewport_x_ratio) || (yr != 0.0 && yr != window->viewport_y_ratio) || (xdpi != window->logical_dpi_x) || (ydpi != window->logical_dpi_y); bool dpi_changed = (xr != 0.0 && xr != window->viewport_x_ratio) || (yr != 0.0 && yr != window->viewport_y_ratio) || (xdpi != window->logical_dpi_x) || (ydpi != window->logical_dpi_y);
window->viewport_size_dirty = true; window->viewport_size_dirty = true;