Use u64
instead of usize
in ElementId
(#29493)
Truncation to a 32 bit `usize` could cause two distinct IDs to be considered the same element. Release Notes: - N/A
This commit is contained in:
parent
bb7a5b13df
commit
60ec55b179
9 changed files with 25 additions and 22 deletions
|
@ -1,5 +1,4 @@
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::usize;
|
|
||||||
use std::{ops::Range, path::Path, sync::Arc};
|
use std::{ops::Range, path::Path, sync::Arc};
|
||||||
|
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
|
@ -85,7 +84,7 @@ impl AgentContext {
|
||||||
/// ID created at time of context add, for use in ElementId. This is not the stable identity of a
|
/// ID created at time of context add, for use in ElementId. This is not the stable identity of a
|
||||||
/// context, instead that's handled by the `PartialEq` and `Hash` impls of `AgentContextKey`.
|
/// context, instead that's handled by the `PartialEq` and `Hash` impls of `AgentContextKey`.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct ContextId(usize);
|
pub struct ContextId(u64);
|
||||||
|
|
||||||
impl ContextId {
|
impl ContextId {
|
||||||
pub fn zero() -> Self {
|
pub fn zero() -> Self {
|
||||||
|
@ -93,7 +92,7 @@ impl ContextId {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn for_lookup() -> Self {
|
fn for_lookup() -> Self {
|
||||||
ContextId(usize::MAX)
|
ContextId(u64::MAX)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn post_inc(&mut self) -> Self {
|
pub fn post_inc(&mut self) -> Self {
|
||||||
|
|
|
@ -388,7 +388,7 @@ impl ContextPicker {
|
||||||
ContextMenuItem::custom_entry(
|
ContextMenuItem::custom_entry(
|
||||||
move |_window, cx| {
|
move |_window, cx| {
|
||||||
render_file_context_entry(
|
render_file_context_entry(
|
||||||
ElementId::NamedInteger("ctx-recent".into(), ix),
|
ElementId::named_usize("ctx-recent", ix),
|
||||||
worktree_id,
|
worktree_id,
|
||||||
&path,
|
&path,
|
||||||
&path_prefix,
|
&path_prefix,
|
||||||
|
|
|
@ -169,7 +169,7 @@ impl PickerDelegate for FileContextPickerDelegate {
|
||||||
.inset(true)
|
.inset(true)
|
||||||
.toggle_state(selected)
|
.toggle_state(selected)
|
||||||
.child(render_file_context_entry(
|
.child(render_file_context_entry(
|
||||||
ElementId::NamedInteger("file-ctx-picker".into(), ix),
|
ElementId::named_usize("file-ctx-picker", ix),
|
||||||
WorktreeId::from_usize(mat.worktree_id),
|
WorktreeId::from_usize(mat.worktree_id),
|
||||||
&mat.path,
|
&mat.path,
|
||||||
&mat.path_prefix,
|
&mat.path_prefix,
|
||||||
|
|
|
@ -171,10 +171,7 @@ impl PickerDelegate for SymbolContextPickerDelegate {
|
||||||
let mat = &self.matches[ix];
|
let mat = &self.matches[ix];
|
||||||
|
|
||||||
Some(ListItem::new(ix).inset(true).toggle_state(selected).child(
|
Some(ListItem::new(ix).inset(true).toggle_state(selected).child(
|
||||||
render_symbol_context_entry(
|
render_symbol_context_entry(ElementId::named_usize("symbol-ctx-picker", ix), mat),
|
||||||
ElementId::NamedInteger("symbol-ctx-picker".into(), ix),
|
|
||||||
mat,
|
|
||||||
),
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub struct CustomBlockId(pub usize);
|
||||||
|
|
||||||
impl From<CustomBlockId> for ElementId {
|
impl From<CustomBlockId> for ElementId {
|
||||||
fn from(val: CustomBlockId) -> Self {
|
fn from(val: CustomBlockId) -> Self {
|
||||||
ElementId::Integer(val.0)
|
val.0.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1065,7 +1065,7 @@ pub struct FoldId(usize);
|
||||||
|
|
||||||
impl From<FoldId> for ElementId {
|
impl From<FoldId> for ElementId {
|
||||||
fn from(val: FoldId) -> Self {
|
fn from(val: FoldId) -> Self {
|
||||||
ElementId::Integer(val.0)
|
val.0.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4046,7 +4046,7 @@ pub enum ElementId {
|
||||||
/// The ID of a View element
|
/// The ID of a View element
|
||||||
View(EntityId),
|
View(EntityId),
|
||||||
/// An integer ID.
|
/// An integer ID.
|
||||||
Integer(usize),
|
Integer(u64),
|
||||||
/// A string based ID.
|
/// A string based ID.
|
||||||
Name(SharedString),
|
Name(SharedString),
|
||||||
/// A UUID.
|
/// A UUID.
|
||||||
|
@ -4054,11 +4054,18 @@ pub enum ElementId {
|
||||||
/// An ID that's equated with a focus handle.
|
/// An ID that's equated with a focus handle.
|
||||||
FocusHandle(FocusId),
|
FocusHandle(FocusId),
|
||||||
/// A combination of a name and an integer.
|
/// A combination of a name and an integer.
|
||||||
NamedInteger(SharedString, usize),
|
NamedInteger(SharedString, u64),
|
||||||
/// A path
|
/// A path
|
||||||
Path(Arc<std::path::Path>),
|
Path(Arc<std::path::Path>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ElementId {
|
||||||
|
/// Constructs an `ElementId::NamedInteger` from a name and `usize`.
|
||||||
|
pub fn named_usize(name: impl Into<SharedString>, integer: usize) -> ElementId {
|
||||||
|
Self::NamedInteger(name.into(), integer as u64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for ElementId {
|
impl Display for ElementId {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
@ -4089,13 +4096,13 @@ impl TryInto<SharedString> for ElementId {
|
||||||
|
|
||||||
impl From<usize> for ElementId {
|
impl From<usize> for ElementId {
|
||||||
fn from(id: usize) -> Self {
|
fn from(id: usize) -> Self {
|
||||||
ElementId::Integer(id)
|
ElementId::Integer(id as u64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<i32> for ElementId {
|
impl From<i32> for ElementId {
|
||||||
fn from(id: i32) -> Self {
|
fn from(id: i32) -> Self {
|
||||||
Self::Integer(id as usize)
|
Self::Integer(id as u64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4125,25 +4132,25 @@ impl<'a> From<&'a FocusHandle> for ElementId {
|
||||||
|
|
||||||
impl From<(&'static str, EntityId)> for ElementId {
|
impl From<(&'static str, EntityId)> for ElementId {
|
||||||
fn from((name, id): (&'static str, EntityId)) -> Self {
|
fn from((name, id): (&'static str, EntityId)) -> Self {
|
||||||
ElementId::NamedInteger(name.into(), id.as_u64() as usize)
|
ElementId::NamedInteger(name.into(), id.as_u64())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(&'static str, usize)> for ElementId {
|
impl From<(&'static str, usize)> for ElementId {
|
||||||
fn from((name, id): (&'static str, usize)) -> Self {
|
fn from((name, id): (&'static str, usize)) -> Self {
|
||||||
ElementId::NamedInteger(name.into(), id)
|
ElementId::NamedInteger(name.into(), id as u64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(SharedString, usize)> for ElementId {
|
impl From<(SharedString, usize)> for ElementId {
|
||||||
fn from((name, id): (SharedString, usize)) -> Self {
|
fn from((name, id): (SharedString, usize)) -> Self {
|
||||||
ElementId::NamedInteger(name, id)
|
ElementId::NamedInteger(name, id as u64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(&'static str, u64)> for ElementId {
|
impl From<(&'static str, u64)> for ElementId {
|
||||||
fn from((name, id): (&'static str, u64)) -> Self {
|
fn from((name, id): (&'static str, u64)) -> Self {
|
||||||
ElementId::NamedInteger(name.into(), id as usize)
|
ElementId::NamedInteger(name.into(), id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4155,7 +4162,7 @@ impl From<Uuid> for ElementId {
|
||||||
|
|
||||||
impl From<(&'static str, u32)> for ElementId {
|
impl From<(&'static str, u32)> for ElementId {
|
||||||
fn from((name, id): (&'static str, u32)) -> Self {
|
fn from((name, id): (&'static str, u32)) -> Self {
|
||||||
ElementId::NamedInteger(name.into(), id as usize)
|
ElementId::NamedInteger(name.into(), id.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1167,7 +1167,7 @@ fn render_copy_code_block_button(
|
||||||
markdown: Entity<Markdown>,
|
markdown: Entity<Markdown>,
|
||||||
cx: &App,
|
cx: &App,
|
||||||
) -> impl IntoElement {
|
) -> impl IntoElement {
|
||||||
let id = ElementId::NamedInteger("copy-markdown-code".into(), id);
|
let id = ElementId::named_usize("copy-markdown-code", id);
|
||||||
let was_copied = markdown.read(cx).copied_code_blocks.contains(&id);
|
let was_copied = markdown.read(cx).copied_code_blocks.contains(&id);
|
||||||
IconButton::new(
|
IconButton::new(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
|
|
|
@ -254,7 +254,7 @@ impl Render for ZedPredictModal {
|
||||||
.text_color(text_color)
|
.text_color(text_color)
|
||||||
.child("tab")
|
.child("tab")
|
||||||
.with_animation(
|
.with_animation(
|
||||||
ElementId::Integer(n),
|
n,
|
||||||
Animation::new(Duration::from_secs(2)).repeat(),
|
Animation::new(Duration::from_secs(2)).repeat(),
|
||||||
move |tab, delta| {
|
move |tab, delta| {
|
||||||
let delta = (delta - 0.15 * n as f32) / 0.7;
|
let delta = (delta - 0.15 * n as f32) / 0.7;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue