mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
Kernel: Add a Range::intersect(other) helper
This commit is contained in:
parent
7b22fb70a2
commit
7874b89426
Notes:
sideshowbarker
2024-07-18 21:26:48 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/7874b89426e Pull-request: https://github.com/SerenityOS/serenity/pull/5510 Issue: https://github.com/SerenityOS/serenity/issues/175 Reviewed-by: https://github.com/BenWiederhake Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/tomuta
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Leon Albrecht <leon2002.la@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -43,5 +44,15 @@ Vector<Range, 2> Range::carve(const Range& taken) const
|
||||
parts.append({ taken.end(), end().get() - taken.end().get() });
|
||||
return parts;
|
||||
}
|
||||
Range Range::intersect(const Range& other) const
|
||||
{
|
||||
if (*this == other) {
|
||||
return *this;
|
||||
}
|
||||
auto new_base = max(base(), other.base());
|
||||
auto new_end = min(end(), other.end());
|
||||
VERIFY(new_base < new_end);
|
||||
return Range(new_base, (new_end - new_base).get());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Leon Albrecht <leon2002.la@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -67,6 +68,7 @@ public:
|
||||
}
|
||||
|
||||
Vector<Range, 2> carve(const Range&) const;
|
||||
Range intersect(const Range&) const;
|
||||
|
||||
private:
|
||||
VirtualAddress m_base;
|
||||
|
Loading…
Reference in New Issue
Block a user