mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-26 23:08:25 +00:00
libghostty: remove selection validation, way too expensive
This commit is contained in:
@@ -178,7 +178,8 @@ typedef enum GHOSTTY_ENUM_TYPED {
|
||||
* @param selection Selection snapshot to adjust in place
|
||||
* @param adjustment The adjustment operation to apply
|
||||
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
|
||||
* selection, selection references, or adjustment are invalid
|
||||
* selection, or adjustment are invalid. Selection reference validity
|
||||
* is a precondition and is not checked.
|
||||
*
|
||||
* @ingroup selection
|
||||
*/
|
||||
@@ -201,7 +202,8 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_adjust(
|
||||
* @param selection Selection snapshot to inspect
|
||||
* @param[out] out_order On success, receives the selection order
|
||||
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
|
||||
* selection, selection references, or output pointer are invalid
|
||||
* selection, or output pointer are invalid. Selection reference
|
||||
* validity is a precondition and is not checked.
|
||||
*
|
||||
* @ingroup selection
|
||||
*/
|
||||
@@ -231,8 +233,8 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_order(
|
||||
* @param desired Desired endpoint order
|
||||
* @param[out] out_selection On success, receives the ordered selection
|
||||
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
|
||||
* selection, selection references, desired order, or output pointer
|
||||
* are invalid
|
||||
* selection, desired order, or output pointer are invalid. Selection
|
||||
* reference validity is a precondition and is not checked.
|
||||
*
|
||||
* @ingroup selection
|
||||
*/
|
||||
@@ -260,7 +262,8 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_ordered(
|
||||
* @param point Point to test for containment
|
||||
* @param[out] out_contains On success, receives whether point is inside selection
|
||||
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
|
||||
* selection, selection references, point, or output pointer are invalid
|
||||
* selection, point, or output pointer are invalid. Selection reference
|
||||
* validity is a precondition and is not checked.
|
||||
*
|
||||
* @ingroup selection
|
||||
*/
|
||||
@@ -281,15 +284,16 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_contains(
|
||||
* for the given terminal's currently active screen. In practice, they must
|
||||
* come from that terminal and screen, and no mutating terminal call may have
|
||||
* occurred since the refs were produced or reconstructed from tracked refs.
|
||||
* Passing refs from another terminal, another screen, or stale refs returns
|
||||
* GHOSTTY_INVALID_VALUE.
|
||||
* Passing refs from another terminal, another screen, or stale refs violates
|
||||
* this precondition.
|
||||
*
|
||||
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
|
||||
* @param a First selection snapshot to compare
|
||||
* @param b Second selection snapshot to compare
|
||||
* @param[out] out_equal On success, receives whether the selections are equal
|
||||
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
|
||||
* selections, selection references, or output pointer are invalid
|
||||
* selections, or output pointer are invalid. Selection reference
|
||||
* validity is a precondition and is not checked.
|
||||
*
|
||||
* @ingroup selection
|
||||
*/
|
||||
@@ -299,24 +303,6 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_equal(
|
||||
const GhosttySelection* b,
|
||||
bool* out_equal);
|
||||
|
||||
/**
|
||||
* Validate that a selection snapshot is representable for a terminal.
|
||||
*
|
||||
* A valid selection has both endpoint grid refs resolved in the terminal's
|
||||
* currently active screen/page list. Malformed refs, stale refs, refs from
|
||||
* another terminal, or refs from an inactive screen return GHOSTTY_INVALID_VALUE.
|
||||
*
|
||||
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
|
||||
* @param selection Selection snapshot to validate
|
||||
* @return GHOSTTY_SUCCESS if the selection is valid for the terminal's active
|
||||
* screen/page list, otherwise GHOSTTY_INVALID_VALUE
|
||||
*
|
||||
* @ingroup selection
|
||||
*/
|
||||
GHOSTTY_API GhosttyResult ghostty_terminal_selection_validate(
|
||||
GhosttyTerminal terminal,
|
||||
const GhosttySelection* selection);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -244,7 +244,6 @@ comptime {
|
||||
@export(&c.terminal_selection_ordered, .{ .name = "ghostty_terminal_selection_ordered" });
|
||||
@export(&c.terminal_selection_contains, .{ .name = "ghostty_terminal_selection_contains" });
|
||||
@export(&c.terminal_selection_equal, .{ .name = "ghostty_terminal_selection_equal" });
|
||||
@export(&c.terminal_selection_validate, .{ .name = "ghostty_terminal_selection_validate" });
|
||||
@export(&c.terminal_grid_ref, .{ .name = "ghostty_terminal_grid_ref" });
|
||||
@export(&c.terminal_grid_ref_track, .{ .name = "ghostty_terminal_grid_ref_track" });
|
||||
@export(&c.terminal_point_from_grid_ref, .{ .name = "ghostty_terminal_point_from_grid_ref" });
|
||||
|
||||
@@ -175,7 +175,6 @@ pub const terminal_selection_order = selection.order;
|
||||
pub const terminal_selection_ordered = selection.ordered;
|
||||
pub const terminal_selection_contains = selection.contains;
|
||||
pub const terminal_selection_equal = selection.equal;
|
||||
pub const terminal_selection_validate = selection.validate;
|
||||
pub const terminal_grid_ref = terminal.grid_ref;
|
||||
pub const terminal_grid_ref_track = terminal.grid_ref_track;
|
||||
pub const terminal_point_from_grid_ref = terminal.point_from_grid_ref;
|
||||
|
||||
@@ -63,7 +63,6 @@ pub fn order(
|
||||
const sel = (selection orelse return .invalid_value).toZig() orelse
|
||||
return .invalid_value;
|
||||
const out = out_order orelse return .invalid_value;
|
||||
if (!valid(t, sel)) return .invalid_value;
|
||||
|
||||
out.* = sel.order(t.screens.active);
|
||||
return .success;
|
||||
@@ -86,7 +85,6 @@ pub fn ordered(
|
||||
const sel = (selection orelse return .invalid_value).toZig() orelse
|
||||
return .invalid_value;
|
||||
const out = out_selection orelse return .invalid_value;
|
||||
if (!valid(t, sel)) return .invalid_value;
|
||||
|
||||
out.* = .fromZig(sel.ordered(t.screens.active, desired));
|
||||
return .success;
|
||||
@@ -102,7 +100,6 @@ pub fn contains(
|
||||
const sel = (selection orelse return .invalid_value).toZig() orelse
|
||||
return .invalid_value;
|
||||
const out = out_contains orelse return .invalid_value;
|
||||
if (!valid(t, sel)) return .invalid_value;
|
||||
|
||||
const screen = t.screens.active;
|
||||
const pin = screen.pages.pin(.fromC(pt)) orelse return .invalid_value;
|
||||
@@ -116,32 +113,13 @@ pub fn equal(
|
||||
b: ?*const CSelection,
|
||||
out_equal: ?*bool,
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const t = terminal_c.zigTerminal(terminal) orelse return .invalid_value;
|
||||
_ = terminal_c.zigTerminal(terminal) orelse return .invalid_value;
|
||||
const sel_a = (a orelse return .invalid_value).toZig() orelse
|
||||
return .invalid_value;
|
||||
const sel_b = (b orelse return .invalid_value).toZig() orelse
|
||||
return .invalid_value;
|
||||
const out = out_equal orelse return .invalid_value;
|
||||
if (!valid(t, sel_a) or !valid(t, sel_b)) return .invalid_value;
|
||||
|
||||
out.* = sel_a.eql(sel_b);
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub fn validate(
|
||||
terminal: terminal_c.Terminal,
|
||||
selection: ?*const CSelection,
|
||||
) callconv(lib.calling_conv) Result {
|
||||
const t = terminal_c.zigTerminal(terminal) orelse return .invalid_value;
|
||||
const sel = (selection orelse return .invalid_value).toZig() orelse
|
||||
return .invalid_value;
|
||||
if (!valid(t, sel)) return .invalid_value;
|
||||
|
||||
return .success;
|
||||
}
|
||||
|
||||
fn valid(t: *terminal_c.ZigTerminal, sel: Selection) bool {
|
||||
const screen = t.screens.active;
|
||||
return screen.pages.pointFromPin(.screen, sel.start()) != null and
|
||||
screen.pages.pointFromPin(.screen, sel.end()) != null;
|
||||
}
|
||||
|
||||
@@ -1552,7 +1552,7 @@ test "selection_contains" {
|
||||
try testing.expect(contains);
|
||||
}
|
||||
|
||||
test "selection_equal and selection_validate" {
|
||||
test "selection_equal" {
|
||||
var t: Terminal = null;
|
||||
try testing.expectEqual(Result.success, new(
|
||||
&lib.alloc.test_allocator,
|
||||
@@ -1626,9 +1626,6 @@ test "selection_equal and selection_validate" {
|
||||
.end = cross_terminal_ref,
|
||||
};
|
||||
|
||||
try testing.expectEqual(Result.success, selection_c.validate(t, &sel));
|
||||
try testing.expectEqual(Result.invalid_value, selection_c.validate(t, &cross_terminal));
|
||||
|
||||
var equal: bool = undefined;
|
||||
try testing.expectEqual(Result.success, selection_c.equal(t, &sel, &equal_sel, &equal));
|
||||
try testing.expect(equal);
|
||||
@@ -1639,7 +1636,8 @@ test "selection_equal and selection_validate" {
|
||||
try testing.expectEqual(Result.success, selection_c.equal(t, &sel, &different_rectangle, &equal));
|
||||
try testing.expect(!equal);
|
||||
|
||||
try testing.expectEqual(Result.invalid_value, selection_c.equal(t, &sel, &cross_terminal, &equal));
|
||||
try testing.expectEqual(Result.success, selection_c.equal(t, &sel, &cross_terminal, &equal));
|
||||
try testing.expect(!equal);
|
||||
try testing.expectEqual(Result.invalid_value, selection_c.equal(t, &sel, &equal_sel, null));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user