mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
get_protocol: don't allocate for protocol string
This commit is contained in:
@@ -281,7 +281,7 @@ pub const HTMLAnchorElement = struct {
|
|||||||
// TODO return a disposable string
|
// TODO return a disposable string
|
||||||
pub fn get_protocol(self: *parser.Anchor, page: *Page) ![]const u8 {
|
pub fn get_protocol(self: *parser.Anchor, page: *Page) ![]const u8 {
|
||||||
var u = try url(self, page);
|
var u = try url(self, page);
|
||||||
return u.get_protocol(page);
|
return u.get_protocol();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_protocol(self: *parser.Anchor, v: []const u8, page: *Page) !void {
|
pub fn set_protocol(self: *parser.Anchor, v: []const u8, page: *Page) !void {
|
||||||
|
|||||||
@@ -41,8 +41,9 @@ pub const Location = struct {
|
|||||||
return page.navigateFromWebAPI(href, .{ .reason = .script });
|
return page.navigateFromWebAPI(href, .{ .reason = .script });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_protocol(self: *Location, page: *Page) ![]const u8 {
|
pub fn get_protocol(self: *Location) []const u8 {
|
||||||
return self.url.get_protocol(page);
|
if (self.url) |*u| return u.get_protocol();
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_host(self: *Location, page: *Page) ![]const u8 {
|
pub fn get_host(self: *Location, page: *Page) ![]const u8 {
|
||||||
|
|||||||
@@ -164,8 +164,11 @@ pub const URL = struct {
|
|||||||
return aw.written();
|
return aw.written();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_protocol(self: *URL, page: *Page) ![]const u8 {
|
pub fn get_protocol(self: *const URL) []const u8 {
|
||||||
return try std.mem.concat(page.arena, u8, &[_][]const u8{ self.uri.scheme, ":" });
|
// std.Uri keeps a pointer to "https", "http" (scheme part) so we know
|
||||||
|
// its followed by ':'.
|
||||||
|
const scheme = self.uri.scheme;
|
||||||
|
return scheme.ptr[0 .. scheme.len + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_username(self: *URL) []const u8 {
|
pub fn get_username(self: *URL) []const u8 {
|
||||||
|
|||||||
Reference in New Issue
Block a user